Bài làm của anh đặng thế phúc. Các bạn tham khảo nha. Nếu có thắc mắc gì hãy vào mục góp ý để lại ý kiến nha. Cảm ơn các bạn.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ThePhuc
{
class node
{
public int x;
public node next;
}
class Program
{
static node l;
static void Nhap()
{
Console.WriteLine("NHAP DAY SO NGUYEN:");
int i = 1; l = null; node p; char kt;
do
{
Console.Write("nhap so thu {0}:", i++);
p = new node();
p.x = int.Parse(Console.ReadLine());
p.next = null;
if (l == null) l = p;//neu ds rong
else
{
node tg = l; node t = null;
while (tg != null && tg.x <= p.x)//dk duyet het ds hoac gap gia tri lon hon gia tri vua nhap
{ t = tg; tg = tg.next; }//t tro vao nut truoc nut tg
if (tg == l) { p.next = l; l = p; } //neu chi co 1 ptu
else
{
if (tg == null) t.next = p;//neu gia tri nhap vao lon hon tat ca cac nut co trong ds
else { t.next = p; p.next = tg; }
}
}
Console.Write("Nhap Tiep?C/K"); kt = char.Parse(Console.ReadLine());
} while (char.ToUpper(kt) == 'C');
}
static void Hien()
{
Console.WriteLine("DANH SACH NHAP LA:");
node p = l;
while (p != null)
{
Console.Write(p.x + "\t");
p = p.next;
}
}
static void Main(string[] args)
{
Nhap();
Hien();
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ThePhuc
{
class node
{
public int x;
public node next;
}
class Program
{
static node l;
static void Nhap()
{
Console.WriteLine("NHAP DAY SO NGUYEN:");
int i = 1; l = null; node p; char kt;
do
{
Console.Write("nhap so thu {0}:", i++);
p = new node();
p.x = int.Parse(Console.ReadLine());
p.next = null;
if (l == null) l = p;//neu ds rong
else
{
node tg = l; node t = null;
while (tg != null && tg.x <= p.x)//dk duyet het ds hoac gap gia tri lon hon gia tri vua nhap
{ t = tg; tg = tg.next; }//t tro vao nut truoc nut tg
if (tg == l) { p.next = l; l = p; } //neu chi co 1 ptu
else
{
if (tg == null) t.next = p;//neu gia tri nhap vao lon hon tat ca cac nut co trong ds
else { t.next = p; p.next = tg; }
}
}
Console.Write("Nhap Tiep?C/K"); kt = char.Parse(Console.ReadLine());
} while (char.ToUpper(kt) == 'C');
}
static void Hien()
{
Console.WriteLine("DANH SACH NHAP LA:");
node p = l;
while (p != null)
{
Console.Write(p.x + "\t");
p = p.next;
}
}
static void Main(string[] args)
{
Nhap();
Hien();
Console.ReadKey();
}
}
}