Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace AiSD1
- {
- class Program
- {
- public class Stec
- {
- int[] S = new int[100];
- int top = 0;
- public void PUSH(int x)
- {
- S[top] = x;
- top++;
- }
- public bool POP()
- {
- if (!ISEMPTY())
- {
- top--;
- return true;
- }
- else
- {
- return false;
- }
- }
- public bool ISEMPTY()
- {
- if (top == 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public void CLAER()
- {
- top = 0;
- }
- public int TOP()
- {
- return S[top - 1];
- }
- }
- public class MyList
- {
- public char data = '0';
- public MyList Next = null;
- }
- public static void Add(char c, MyList Head)
- {
- if(Head.data == '0')
- {
- Head.data = c;
- Head.Next = null;
- return;
- }
- if(Head.Next == null)
- {
- MyList newElement = new MyList();
- newElement.data = c;
- Head.Next = newElement;
- newElement.Next = null;
- if (c < Head.data)
- {
- newElement.data = Head.data;
- Head.data = c;
- }
- return;
- }
- if(Head.data > c)
- {
- //сделать новый элемент после Head, записать туда данные из Head, а в Head записать данные нового элемента
- MyList tmp = Head.Next;
- Head.Next = new MyList();
- Head.Next.Next = tmp;
- Head.Next.data = Head.data;
- Head.data = c;
- }
- while(Head.Next.data < c)
- {
- Head = Head.Next;
- }
- MyList newElem = new MyList();
- newElem.data = c;
- newElem.Next = Head.Next;
- Head.Next = newElem;
- }
- public static bool Remove(char c, MyList Head)
- {
- if(Head == null || Head.data == '0')
- {
- return false;
- }
- if(Head.data == c)
- {
- Head.data = Head.Next.data;
- Head.Next = Head.Next.Next;
- return true;
- }
- while (Head.Next.data != c)
- {
- if (Head.Next.Next == null)
- {
- return false;
- }
- Head = Head.Next;
- }
- Head.Next = Head.Next.Next;
- return true;
- }
- public static int FindePos(char c, MyList Head)
- {
- int i = 0;
- while (Head.data != c)
- {
- i++;
- if (Head.Next == null)
- {
- return -1;
- }
- Head = Head.Next;
- }
- return i;
- }
- public static void Clear(MyList Head)
- {
- Head = null;
- }
- static void Main(string[] args)
- {
- //Stec S = new Stec();
- //Console.WriteLine("Put -1 to close");
- //Console.WriteLine("Enter comand: ");
- //string s = Console.ReadLine();
- //string[] sw = new string[2];
- //while(s != "-1")
- //{
- // sw = s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- // switch (sw[0])
- // {
- // case "PUSH":
- // S.PUSH(sw[1][0] - '0');
- // break;
- // case "POP":
- // S.POP();
- // break;
- // case "TOP":
- // Console.WriteLine(S.TOP());
- // break;
- // case "CLEAR":
- // S.CLAER();
- // break;
- // case "ISEMPTY":
- // Console.WriteLine(S.ISEMPTY());
- // break;
- // }
- // Console.WriteLine("Enter comand: ");
- // s = Console.ReadLine();
- //}
- MyList Head = new MyList();
- Add('b', Head);
- Add('c', Head);
- Add('a', Head);
- Remove('f', Head);
- Console.WriteLine((FindePos('c', Head) + 1).ToString());
- while (Head != null)
- {
- Console.Write(Head.data.ToString() + ' '.ToString());
- Head = Head.Next;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement