Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace LinkedListt
- {
- class List
- {
- Node start = null;
- public void add(int val)
- {
- Node tmp = new Node(val);
- if(start == null)
- {
- start = tmp;
- return;
- }
- Node q = start;
- while (q.next != null)
- {
- q = q.next;
- }
- q.next = tmp;
- }
- public void addbeg(int val)
- {
- Node tmp = new Node(val);
- tmp.next = start;
- start = tmp;
- }
- public void reverse()
- {
- List l = new List();
- Node q = start;
- while (q != null)
- {
- l.addbeg(q.info);
- q = q.next;
- }
- start = l.start;
- }
- public void RemoveDub()
- {
- if (start == null)
- {
- return;
- }
- Node q = start;
- while (q.next.next != null)
- {
- if (q.info == q.next.info)
- {
- q.next = q.next.next;
- }
- q = q.next;
- }
- if (q.info == q.next.info)
- {
- q.next = null;
- }
- }
- public void print()
- {
- if(start == null) return;
- Node q = start;
- while(q != null)
- {
- Console.WriteLine(q.info);
- q = q.next;
- }
- }
- public void delete(int val)
- {
- if (start.info == val)
- {
- start = start.next;
- }
- Node q = start;
- while (q.next.next != null)
- {
- if (q.next.info == val)
- {
- q = q.next.next;
- }
- q = q.next;
- }
- if (q.next.info == val)
- {
- q.next = null;
- }
- }
- public void sort()
- {
- Node q = start;
- while (q != null)
- {
- Node Q = q.next;
- while (Q != null)
- {
- if (Q.info < q.info)
- {
- int tmp = q.info;
- q.info = Q.info;
- Q.info = tmp;
- }
- Q = Q.next;
- }
- q = q.next;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement