Advertisement
Zhanna_K

Untitled

Feb 25th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.86 KB | None | 0 0
  1. namespace ConsoleApplication7
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Text;
  7.  
  8.     namespace ConsoleApplication2
  9.     {
  10.         public class myCell
  11.         {
  12.             public string name;
  13.             public myCell next;
  14.         }
  15.  
  16.  
  17.         public class myStack
  18.         {
  19.             public myCell first = new myCell();
  20.             public int i;
  21.             public string str;
  22.             public myCell tmp, link;
  23.  
  24.            
  25.  
  26.             public void Push(string a, myCell link)
  27.             {
  28.                 myCell tmp = new myCell();
  29.                 tmp.name = a;
  30.                 tmp.next = first.next;
  31.                 first.next = tmp;
  32.  
  33.             }
  34.             public bool Exist(string a, myCell link)
  35.             {
  36.                 bool ex = false;
  37.                 link = first;
  38.                 while (link.next != null)
  39.                 {
  40.                     link = link.next;
  41.                     if (link.name == a)
  42.                     { ex = true; };
  43.                 }
  44.                 return ex;
  45.             }
  46.             public string Print()
  47.             {
  48.                 str = " ";
  49.                 myCell link = first;
  50.                 while (link.next != null)
  51.                 {
  52.                     link = link.next;
  53.                     str = str + link.name + ",";
  54.                 }
  55.                 return str;
  56.             }
  57.  
  58.             public void Pop(string a)
  59.             {
  60.  
  61.                 link = first;
  62.                 while (link.next.name != a)
  63.                 { a = first.next.name; }
  64.                 first.next = first.next.next;
  65.  
  66.  
  67.             }
  68.  
  69.         }
  70.  
  71.     }
  72.     }
  73.  
  74.  
  75.  
  76. class Program
  77. {
  78.     static void Main(string[] args)
  79.     {
  80.         Console.WriteLine("Список студентов. \n Для выполнения функций ниже нажмите соответствующую клавишу и Enter");
  81.         Console.WriteLine("1-добавление элемента.\n2 удаление элемента.\n3 вывод всех.");
  82.         myStack Stack = new myStack();
  83.  
  84.     M:;
  85.         string a, f = Console.ReadLine();
  86.         switch (f)
  87.         {
  88.             case "1":
  89.                 {
  90.                     Console.WriteLine("введите наименованте для добавления ");
  91.                     a = Console.ReadLine();
  92.                     Stack.link = Stack.first;
  93.                     while (Stack.link.next != null)
  94.                     { Stack.link = Stack.link.next; }
  95.                     Stack.Push(a, Stack.link); goto M;
  96.                 };
  97.  
  98.             case "2":
  99.                 {
  100.                     {
  101.                         Console.WriteLine("Введите наименование, которое необходимо удалить (учитывайте регистр):");
  102.                         a = Console.ReadLine();
  103.  
  104.                         if (Stack.Exist(a, Stack.first))
  105.                         Stack.Pop(a);
  106.                          else { Console.WriteLine("Данного наименования не существует"); }
  107.                     }
  108.                     goto M;
  109.                 };
  110.                
  111.  
  112.             case "3":
  113.                 {
  114.                     Stack.Print();
  115.                     Console.WriteLine(Stack.str);
  116.                 }
  117.                 goto M;
  118.  
  119.             default:
  120.  
  121.                 {
  122.                     Console.WriteLine("Веденное значение не соответствует ни одной из команд, попробуйте еще раз");
  123.                     goto M;
  124.                 }
  125.         }
  126.  
  127.     }
  128. }
  129.  
  130.                     break;
  131.                 case 2:
  132.  
  133.                     break;
  134.                 case 3:
  135.  
  136.                     break;
  137.                 case 4:
  138.  
  139.                     break;
  140.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement