Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- link<int> a = new link<int> { };
- a.addFirst(new node<int>(1));
- a.add(2);
- a.add(3);
- a.add(4);
- a.print();
- // a.removeAfter(????);
- a.print();
- }
- }
- class node<T>
- {
- public T data;
- public node<T> next;
- public node(T data)
- {
- this.data = data;
- }
- }
- class link<T>
- {
- node<T> firstNode;
- node<T> lastnode;
- public void add(T Node)
- {
- node<T> newnode = new node<T>(Node);
- lastnode.next = newnode;
- lastnode = newnode;
- }
- public void addFirst(node<T> newNode)
- {
- newNode.next = firstNode;
- firstNode = lastnode= newNode;
- }
- public void removeAfter(node<T> node)
- {
- node.next = node.next.next;
- }
- public void removeBeggining(link<T> link)
- {
- if (link.firstNode.next != null)
- {
- link.firstNode = link.firstNode.next;
- }
- }
- public void print()
- {
- node<T> node = firstNode;
- while (node != null)
- {
- Console.WriteLine(node.data);
- if (node.next != null)
- {
- node = node.next;
- }
- else
- {
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment