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;
- }
- 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();
- S.PUSH(1);
- S.PUSH(2);
- S.PUSH(3);
- S.PUSH(4);
- S.POP();
- Console.WriteLine(S.TOP());
- S.PUSH(17);
- Console.WriteLine(S.TOP());
- Console.WriteLine(S.ISEMPTY());
- S.CLAER();
- Console.WriteLine(S.ISEMPTY());
- Console.WriteLine(' ');
- MyList Head = new MyList();
- Remove('b', 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