Skip to main content

Posts

Showing posts from April, 2015

How to implement Stack using linked list

Stacks are easier to implement using linked lists. There is no need to set a limit on the size of the stackusing System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LinkedlistUsingStack { public class Node { public int Data { get; set; } public Node Next { get; set; } public Node(int data) { this.Data = data; } } public class Stack { private Node _stackTop; public void Push(int newValue) { Node newNode = new Node(newValue); newNode.Next = _stackTop; _stackTop = newNode; } public bool IsEmpty() { return _stackTop == null; } public int Pop() { Node temp = _stackTop; var data = temp.Data; _stackTop = temp.Next; return data; } public void Print() { …