Guest User

Untitled

a guest
Jun 22nd, 2014
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             link<int> a = new link<int> { };
  13.             a.addFirst(new node<int>(1));
  14.             a.add(2);
  15.             a.add(3);
  16.             a.add(4);
  17.             a.print();
  18.        //    a.removeAfter(????);
  19.             a.print();
  20.         }
  21.     }
  22.     class node<T>
  23.     {
  24.         public T data;
  25.         public node<T> next;
  26.         public node(T data)
  27.         {
  28.             this.data = data;
  29.         }
  30.     }
  31.     class link<T>
  32.     {
  33.         node<T> firstNode;
  34.         node<T> lastnode;
  35.         public void add(T Node)
  36.         {
  37.             node<T> newnode = new node<T>(Node);
  38.             lastnode.next = newnode;
  39.             lastnode = newnode;
  40.         }
  41.         public void addFirst(node<T> newNode)
  42.         {
  43.             newNode.next = firstNode;
  44.             firstNode = lastnode= newNode;
  45.         }
  46.         public void removeAfter(node<T> node)
  47.         {
  48.             node.next = node.next.next;
  49.         }
  50.         public void removeBeggining(link<T> link)
  51.         {
  52.             if (link.firstNode.next != null)
  53.             {
  54.                 link.firstNode = link.firstNode.next;
  55.             }
  56.         }
  57.         public void print()
  58.         {
  59.             node<T> node = firstNode;
  60.             while (node != null)
  61.             {
  62.                 Console.WriteLine(node.data);
  63.                 if (node.next != null)
  64.                 {
  65.                     node = node.next;
  66.                 }
  67.                 else
  68.                 {
  69.                     break;
  70.                 }
  71.             }
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment