-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstackplates.java
More file actions
60 lines (51 loc) · 1.27 KB
/
stackplates.java
File metadata and controls
60 lines (51 loc) · 1.27 KB
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
package edu.java.chap3;
//import java.util.Stack;
/*
* start a new stack when the previous stack exceeds some threshold
* implement a data structure setofstacks that mimics this.SetOfStacks should be composed of several stacks, and should
* create a new stack once the previous one exceeds capacity SetOfStacks push() and SetOfStacks pop() should behave
* identically to a single stack (that is, pop() should return the same values as it would if there were just a
* single stack)
*
*/
/*
public class StackPlates {
public static void main(String[] args) {
Stacks st = new Stacks();
Stacks temp = new Stacks();
temp.push(1);
st.push(temp);
Stacks s1 = new Stacks(st);
s1.push(2);
System.out.println(s1.pop());
}
}
class Stacks{
stack st;
int pos;
int capacity = 10;
public Stacks(stack st){
this.st = st;
pos = 0;
}
Object pop(){
if(st.top!=null){
stack target = (stack)st.peek();
Object item = target.pop();
return item;
}
return null;
}
void push(Object item){
if(pos==capacity-1){
stack temp = new stack();
st.push(temp);
temp.push(item);
}
else{
((stack) st.peek()).push(item);
pos++;
}
}
}
*/