Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApplication7
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication2
- {
- public class myCell
- {
- public string name;
- public myCell next;
- }
- public class myStack
- {
- public myCell first = new myCell();
- public int i;
- public string str;
- public myCell tmp, link;
- public void Push(string a, myCell link)
- {
- myCell tmp = new myCell();
- tmp.name = a;
- tmp.next = first.next;
- first.next = tmp;
- }
- public bool Exist(string a, myCell link)
- {
- bool ex = false;
- link = first;
- while (link.next != null)
- {
- link = link.next;
- if (link.name == a)
- { ex = true; };
- }
- return ex;
- }
- public string Print()
- {
- str = " ";
- myCell link = first;
- while (link.next != null)
- {
- link = link.next;
- str = str + link.name + ",";
- }
- return str;
- }
- public void Pop(string a)
- {
- link = first;
- while (link.next.name != a)
- { a = first.next.name; }
- first.next = first.next.next;
- }
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Список студентов. \n Для выполнения функций ниже нажмите соответствующую клавишу и Enter");
- Console.WriteLine("1-добавление элемента.\n2 удаление элемента.\n3 вывод всех.");
- myStack Stack = new myStack();
- M:;
- string a, f = Console.ReadLine();
- switch (f)
- {
- case "1":
- {
- Console.WriteLine("введите наименованте для добавления ");
- a = Console.ReadLine();
- Stack.link = Stack.first;
- while (Stack.link.next != null)
- { Stack.link = Stack.link.next; }
- Stack.Push(a, Stack.link); goto M;
- };
- case "2":
- {
- {
- Console.WriteLine("Введите наименование, которое необходимо удалить (учитывайте регистр):");
- a = Console.ReadLine();
- if (Stack.Exist(a, Stack.first))
- Stack.Pop(a);
- else { Console.WriteLine("Данного наименования не существует"); }
- }
- goto M;
- };
- case "3":
- {
- Stack.Print();
- Console.WriteLine(Stack.str);
- }
- goto M;
- default:
- {
- Console.WriteLine("Веденное значение не соответствует ни одной из команд, попробуйте еще раз");
- goto M;
- }
- }
- }
- }
- break;
- case 2:
- break;
- case 3:
- break;
- case 4:
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement