-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntStack.java
executable file
·188 lines (154 loc) · 3.46 KB
/
IntStack.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import java.util.Arrays;
public class IntStack {
public static void main(String[] args) {
IntStack is = new IntStack();
System.out.println(is.isEmpty());
is.push(3);
is.push(4);
is.push(5);
System.out.println(is.isEmpty());
System.out.println(is.pop());
System.out.println(is.peek());
//testing area for sort -Elie
IntStack elie = new IntStack();
elie.push(3);
elie.push(2);
elie.push(5);
elie.push(1);
elie.push(9);
elie.sort();
System.out.println("sorted? " + Arrays.toString(elie.stack));
//Ryo Test
is.print();
//Jared Test
IntStack Jared = new IntStack();
Jared.push(10);
Jared.push(11);
Jared.push(12);
Jared.push(13);
int[] multiple = Jared.pop(3);
System.out.println(Arrays.toString(multiple));
//Ryan Test
IntStack ryan = new IntStack();
int[] test = {1,2,3};
ryan.push(test);
System.out.println(Arrays.toString(ryan.stack));
System.out.println("ryan's stack");
}
int[] stack;
int top;
public IntStack() {
stack = new int[100];
top = 0;
}
boolean isEmpty() {
return top==0;
}
void push(int i) {
if(top==stack.length) resize();
stack[top++]=i;
}
int pop() {
if(!isEmpty()) return stack[--top];
return -1;
}
int peek() {//sometimes
if(!isEmpty()) return stack[top-1];
return -1;
}
/*
make a new larger implementing array
*/
private void resize() {
int[] temp = new int[stack.length*stack.length];
for (int i = 0; i < stack.length; i++) {
temp[i] = stack[i];
}
stack = temp;
}
/*
how large is the stack?
*/
public int size() {
return 0;
}
/*
sort the contents of the stack
*/
public void sort() {
//sorts stack
Arrays.sort(stack);
//flips order of stack, largest to smallest
for (int i = 0; i < stack.length/2; i++) {
int temp = stack[i];
stack[i] = stack[stack.length-1-i];
stack[stack.length-1-i] = temp;
}
}
/*
print the Stack pretty-like
*/
public void print() {
for(int i = 0; i < top; i++){
System.out.print(stack[i] + " ");
}
System.out.println();
}
/*
return the item depth distance from the top
*/
public int peek(int depth) {
return 0;
}
/*
return multiple items from the top in a new array
*/
public int[] pop(int multiple) {
int[] array = new int[multiple];
for (int i = 0; i < multiple; i++) {
array[i] = pop();
}
return array;
}
/*
push multiple items onto the stack
*/
public void push(int[] nums) {
for(int a = 0; a < nums.length; a++){
push(nums[a]);
}
}
/*
how many [num]'s are n the stack?
*/
public int count(int num) {
return 0;
}
/*
remove depth items
*/
public void dump(int depth) {
}
/*
return the contents of the stack as an array
*/
public int[] toArray() {
return null;
}
/*
make the bottom of the stack the top
*/
public void flip() {
}
/*
return a new stack that includes the top size items.
*/
public IntStack subStack(int size) {
return null;
}
/*
divide every item in the stack by mult
*/
public void divStack(int mult) {
}
}