using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bai_2._7
{
class node
{
public int ph;
public node love;
}
class Program
{
static node l;
static void Nhap()
{
Console.WriteLine("nhap vao day so nguyen:");
int i = 1; l = null; node tg; char kt;
do
{
Console.WriteLine("nhap so nguyen thu:" + i++);
tg = new node();
Console.Write("ph="); tg.ph = int.Parse(Console.ReadLine());
tg.love = null;
if (l == null)
l = tg;
else
{
tg.love = l; l = tg;
}
Console.WriteLine("ban co muon nhap tiep c/k");
kt = char.Parse(Console.ReadLine());
} while (char.ToUpper(kt) == 'C');
}
static void hien()
{
node tg = l;
while (tg != null)
{
Console.Write(tg.ph + "\t");
tg = tg.love;
}
Console.WriteLine();
}
static void dem()
{
node tg = l;
int dem = 0;
while (tg != null)
{
dem = dem + 1;
tg = tg.love;
}
Console.WriteLine("so luong nut trong danh sach la:" + dem);
}
static void demmax()
{
int dem = 0;
node tg = l;
while (tg != null)
{
if (tg.ph > 0)
{
dem = dem + 1;
tg = tg.love;
}
else
tg = tg.love;
}
Console.WriteLine("so nut duong trong danh sach la:" + dem);
}
static void Main(string[] args)
{
Nhap();
hien();
dem();
demmax();
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bai_2._7
{
class node
{
public int ph;
public node love;
}
class Program
{
static node l;
static void Nhap()
{
Console.WriteLine("nhap vao day so nguyen:");
int i = 1; l = null; node tg; char kt;
do
{
Console.WriteLine("nhap so nguyen thu:" + i++);
tg = new node();
Console.Write("ph="); tg.ph = int.Parse(Console.ReadLine());
tg.love = null;
if (l == null)
l = tg;
else
{
tg.love = l; l = tg;
}
Console.WriteLine("ban co muon nhap tiep c/k");
kt = char.Parse(Console.ReadLine());
} while (char.ToUpper(kt) == 'C');
}
static void hien()
{
node tg = l;
while (tg != null)
{
Console.Write(tg.ph + "\t");
tg = tg.love;
}
Console.WriteLine();
}
static void dem()
{
node tg = l;
int dem = 0;
while (tg != null)
{
dem = dem + 1;
tg = tg.love;
}
Console.WriteLine("so luong nut trong danh sach la:" + dem);
}
static void demmax()
{
int dem = 0;
node tg = l;
while (tg != null)
{
if (tg.ph > 0)
{
dem = dem + 1;
tg = tg.love;
}
else
tg = tg.love;
}
Console.WriteLine("so nut duong trong danh sach la:" + dem);
}
static void Main(string[] args)
{
Nhap();
hien();
dem();
demmax();
Console.ReadKey();
}
}
}