-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack copy(linkedlist).java
79 lines (79 loc) · 1.24 KB
/
stack copy(linkedlist).java
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
78
79
class stack extends LinkedList
{
void push(int n)
{
if(START == null)
{
AddAtStart(n);
}
else
{
AddAtEnd(n);
}
}
void pop()
{
if(size == 0)
{
System.out.println("Empty stack");
}
else
{
System.out.println("The popped element is "+remove(size-1));
}
}
void peep()
{
Node temp = new Node();
temp = START;
if(START == null)
{
System.out.println("empty");
}
else
{
while(temp.next!=null)
{
temp = temp.next;
}
System.out.println("The topmost element is "+temp.data);
}
}
void search(int n)
{
if(START == null)
{
System.out.println("empty");
}
else
{
int counter=0;
Node temp = new Node();
temp = START;
while(temp.next!=null)
{
if(temp.data == n)
{
counter = 1;
break;
}
else
{
temp=temp.next;
}
}
if(counter == 1)
{
System.out.println("Element found");
}
else
{
System.out.println("No such element is present");
}
}
}
void check_size()
{
System.out.println("The current size of stack is "+size);
}
}