Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace AiSD1
- {
- class Program
- {
- 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)
- {
- 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)
- {
- MyList Head = new MyList();
- Add('f', Head);
- Add('a', Head);
- Add('b', Head);
- Add('c', 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