hamzajaved

Linked List

Nov 6th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. namespace ConsoleApplication14
  2. {
  3.  
  4.  
  5.   public  class Node
  6.     {
  7.         public int value;
  8.         public Node Next;
  9.  
  10.         public Node(int val)
  11.         {
  12.             value = val;
  13.             Next = null;
  14.         }
  15.     }
  16.     public class SingleLL
  17.     {
  18.         public Node Head;
  19.         public Node Tail;
  20.         public SingleLL()
  21.         {
  22.             Head = null;
  23.             Tail = null;
  24.         }
  25.         public void Add(int val)
  26.         {
  27.             Node n = new Node(val);
  28.             if (Head == null)
  29.             {
  30.                 Head = n;
  31.                 Tail = n;
  32.             }
  33.             else
  34.             {
  35.                 Tail.Next = n;
  36.                 Tail = Tail.Next;
  37.  
  38.             }
  39.         }
  40.  
  41.  
  42.         public void Print()
  43.         {
  44.             Node cur = Head;
  45.             while (cur != null)
  46.             {
  47.                 Console.WriteLine(cur.value);
  48.                 cur = cur.Next;
  49.             }
  50.         }
  51.     }
  52.     class Program
  53.     {
  54.         static void Main(string[] args)
  55.         {
  56.             SingleLL ss = new SingleLL();
  57.             ss.Add(5);
  58.             ss.Add(10);
  59.             ss.Print();
  60.             Console.Read();
  61.  
  62.         }
  63.  
  64.     }
  65. }
Add Comment
Please, Sign In to add comment