View difference between Paste ID: DMXDcUUQ and 2Uz8nVuU
SHOW: | | - or go back to the newest paste.
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(1);
15
            a.add(2);
16
            a.add(3);
17
            a.add(4);
18
            a.add(1);
19
            a.print();
20
            a.removeAfter(????);
21
            a.print();
22
        }
23
    }
24
    class node<T>
25
    {
26
        public T data;
27
        public node<T> next;
28
        public node(T data)
29
        {
30
            this.data = data;
31
        }
32
    }
33
    class link<T>
34
    {
35
        node<T> firstNode;
36
        node<T> lastnode;
37
        public void add(T Node)
38
        {
39
                node<T> newnode = new node<T>(Node);
40
                newnode.next = this.lastnode.next;
41
                lastnode.next = newnode;
42
           
43
        }
44
        public void addFirst( node<T> newNode)
45
        {
46
            newNode.next = firstNode;
47-
            firstNode =lastnode= newNode;
47+
            firstNode = newNode;
48
        }
49
        public void removeAfter(node<T> node)
50
        {
51
            node.next = node.next.next;
52
        }
53
        public void removeBeggining(link<T> link)
54
        {
55
            if (link.firstNode.next != null)
56
            {
57
                link.firstNode = link.firstNode.next;
58
            }
59
        }
60
        public void print()
61
        {
62
            node<T> node = firstNode;
63
            while (node.next != null)
64
            {
65
                Console.WriteLine(node.data);
66
                if (node.next != null)
67
                {
68
                    node = node.next;
69
                }
70
            }
71
        }
72
    }
73
}