hamzajaved

Linked List Generic

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