-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path13 ● Stack_using_LinkedList.cs
77 lines (77 loc) · 1.61 KB
/
13 ● Stack_using_LinkedList.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
namespace StackLL
{
class Node
{
public int data;
public Node next;
}
class List
{
public int top;
public Node head;
public List()
{
head = null;
top = -1;
}
public void push(int item)
{
Node temp = new Node();
temp.data = item;
temp.next = head;
head = temp;
top++;
}
public void pop()
{
if(is_empty())
{
Console.WriteLine("Empty Stack");
return ;
}
Console.WriteLine(head.data);
head = head.next;
top--;
}
public bool is_empty()
{
return top<0;
}
public void peek()
{
Console.WriteLine(head.data);
}
public void display()
{
Node p = head;
while (p != null)
{
Console.Write(p.data + " ");
p = p.next;
}
Console.WriteLine();
}
public void size()
{
Console.WriteLine("Stack size = {0}", (top+1));
}
}
class Program
{
static void Main(string[] args)
{
List L = new List();
if (L.is_empty())
{ Console.WriteLine("Empty Stack"); }
L.push(10);
L.push(11);
L.push(12);
L.peek();
L.size();
L.pop();
L.is_empty();
L.display();
}
}
}