Advertisement
haquaa

Untitled

Jan 4th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace LinkedListt
  7. {
  8.     class List
  9.     {
  10.         Node start = null;
  11.  
  12.         public void add(int val)
  13.         {
  14.             Node tmp = new Node(val);
  15.             if(start == null)
  16.             {
  17.                 start = tmp;
  18.                 return;
  19.             }
  20.  
  21.             Node q = start;
  22.             while (q.next != null)
  23.             {
  24.                 q = q.next;
  25.             }
  26.  
  27.             q.next = tmp;
  28.         }
  29.  
  30.         public void addbeg(int val)
  31.         {
  32.             Node tmp = new Node(val);
  33.             tmp.next = start;
  34.             start = tmp;
  35.         }
  36.  
  37.         public void reverse()
  38.         {
  39.             List l = new List();
  40.             Node q = start;
  41.             while (q != null)
  42.             {
  43.                 l.addbeg(q.info);
  44.                 q = q.next;
  45.             }
  46.             start = l.start;
  47.         }
  48.  
  49.         public void RemoveDub()
  50.         {
  51.             if (start == null)
  52.             {
  53.                 return;
  54.             }
  55.  
  56.             Node q = start;
  57.  
  58.             while (q.next.next != null)
  59.             {  
  60.                 if (q.info == q.next.info)
  61.                 {
  62.                     q.next = q.next.next;
  63.                 }
  64.                 q = q.next;
  65.             }
  66.             if (q.info == q.next.info)
  67.             {
  68.                 q.next = null;
  69.             }
  70.         }
  71.  
  72.         public void print()
  73.         {
  74.              if(start == null) return;
  75.              Node q = start;
  76.              while(q != null)
  77.              {
  78.                  Console.WriteLine(q.info);
  79.                  q = q.next;
  80.              }
  81.          }
  82.  
  83.         public void delete(int val)
  84.         {
  85.             if (start.info == val)
  86.             {
  87.                 start = start.next;
  88.             }
  89.             Node q = start;
  90.             while (q.next.next != null)
  91.             {
  92.                 if (q.next.info == val)
  93.                 {
  94.                     q = q.next.next;
  95.                 }
  96.                 q = q.next;
  97.             }
  98.             if (q.next.info == val)
  99.             {
  100.                 q.next = null;
  101.             }
  102.         }
  103.  
  104.         public void sort()
  105.         {
  106.             Node q = start;
  107.             while (q != null)
  108.             {
  109.                 Node Q = q.next;
  110.                 while (Q != null)
  111.                 {
  112.                     if (Q.info < q.info)
  113.                     {
  114.                         int tmp = q.info;
  115.                         q.info = Q.info;
  116.                         Q.info = tmp;
  117.                     }
  118.                     Q = Q.next;
  119.                 }
  120.                 q = q.next;
  121.             }
  122.         }
  123.  
  124.  
  125.      }
  126.  
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement