Стек, Очередь, Двусвязный список - C#
Формулировка задачи:
сначала нужно сформировать и заполнить элементами три структуры – «стек», «очередь», «двусвязный список». Для проверки вывести их на экран)
Спасибо.
Решение задачи: «Стек, Очередь, Двусвязный список»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace New
{
class Student
{
string name;
string surname;
int age;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public string Surname
{
get
{
return surname;
}
set
{
surname = value;
}
}
public int Age
{
get
{
return age;
}
set
{
age = value;
}
}
public override string ToString()
{
return string.Format(this.Name+" "+this.Surname+" "+this.Age);
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Очередь");
Queue<Student> st = new Queue<Student>();
st.Enqueue(new Student { Name = "Sergey", Surname = "Ivanov", Age = 19 });
st.Enqueue(new Student { Name = "Alex", Surname = "Petrov", Age = 20 });
st.Enqueue(new Student { Name = "Sova", Surname = "Garry Pottera", Age = 21 });
foreach (Student s in st)
{
Console.WriteLine(s.ToString());
}
Console.WriteLine("Стэк");
Stack<Student> st1 = new Stack<Student>();
st1.Push(new Student { Name = "Sergey", Surname = "Ivanov", Age = 19 });
st1.Push(new Student { Name = "Alex", Surname = "Petrov", Age = 20 });
st1.Push(new Student { Name = "Sova", Surname = "Garry Pottera", Age = 21 });
foreach (Student s in st1)
{
Console.WriteLine(s.ToString());
}
Console.WriteLine("Двусвязный список");
List<Student> st2 =new List<Student>();
st2.Add(st.Peek());
st2.Add(st1.Peek());
foreach (Student s in st2)
{
Console.WriteLine(s.ToString());
}
Console.ReadKey();
}
}
}