-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathourStack.java
51 lines (44 loc) · 939 Bytes
/
ourStack.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
package dataStructure;
public class ourStack<T> extends ourLinkedList<T>{
public ourStack() {
super();
}
public void push(T data){
this.append(data);
}
public T pop() throws listIndexOutOfBound{
T temp = this.get(this.size-1);
this.delete(this.size-1);
return temp;
}
public ourStack<T> reverse() throws listIndexOutOfBound{
ourStack<T> temp = new ourStack<T>();
int count = this.size-1;
while(count>-1){
temp.push(this.get(count));
count--;
}
return temp;
}
public void swap(ourStack<T> st2) throws listIndexOutOfBound
{
if(this.size != st2.size)
{
System.out.println("Can not be swap");
}
ourStack<T> temp = new ourStack<T>();
int i;
while(!this.isEmpty())
{
temp.append(this.pop());
}
while(!st2.isEmpty())
{
this.append(st2.pop());
}
while(!temp.isEmpty())
{
st2.append(temp.pop());
}
}
}