-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntStack.java
More file actions
84 lines (70 loc) · 1.42 KB
/
IntStack.java
File metadata and controls
84 lines (70 loc) · 1.42 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
public class IntStack implements StackIntADT
{
// fields
private int[] stack;
private int pointer, size;
// constructors
public IntStack( int sizes)
{
stack = new int[sizes];
pointer = -1;
size = sizes;
}//end construct 1
public IntStack()
{
stack = new int[10];
pointer = -1;
size = 10;
}//end construct default
// stack class methods {NOT FINISHED}
public void push(int element) //pushes onto stack
{
if (isFull())
{
System.out.println("stack is full");
}
else
{
pointer++;
stack[pointer] = element;
}
}//end push
public int pop() //popps from stack
{
int popped;
if (!isEmpty())
{
popped = stack[pointer];
pointer--;
}//end if
else
{
System.out.println("Stack is Empty");
popped = 0;
}//end else
return popped;
}//end pop
public int peek() //looks at the top of the stack
{
if (!isEmpty())
{
return stack[pointer];
}
else
{
return pointer;
}
}//end peek
public boolean isEmpty() // check emptyness
{
return pointer == -1;
}
public boolean isFull() // check fullness
{
return pointer == (size - 1);
}
public int size() // chekcs size
{
return pointer++;
}
}//end class