Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace FSM
- {
- class Node
- {
- public int data;
- public Node next;
- public Node(int data)
- {
- this.data = data;
- this.next = null;
- }
- }
- }
- namespace FSM
- {
- class LinkedList
- {
- public Node head;
- public int count;
- public LinkedList()
- {
- this.head = null;
- this.count = 0;
- }
- public void AddBegin(int val)
- {
- Node n = new Node(val);
- n.next = this.head;
- this.head = n;
- this.count++;
- }
- public void PrintList()
- {
- Node current = this.head;
- while(current != null)
- {
- Console.Write(current.data + " ");
- current = current.next;
- }
- Console.WriteLine();
- }
- public void RemoveFirst()
- {
- if (this.head == null)
- {
- return;
- }
- this.head = this.head.next;
- }
- public void AddEnd(int val)
- {
- Node n = new Node(val);
- if (this.head == null)
- {
- this.head = n;
- return;
- }
- Node current = this.head;
- while (current.next != null)
- {
- current = current.next;
- }
- current.next = n;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement