-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackSort.java
More file actions
80 lines (67 loc) · 1.79 KB
/
Copy pathStackSort.java
File metadata and controls
80 lines (67 loc) · 1.79 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
public class StackSort {
static class Node {
int value;
Node next;
public Node(int value) {
this.value = value;
}
}
static class Stack {
private Node top;
private int length;
public Stack(int value) {
Node newNode = new Node(value);
this.top = newNode;
this.length = 1;
}
public Stack() {
}
public void push(int value) {
Node newNode = new Node(value);
if (this.length == 0) {
this.top = newNode;
this.length = 1;
} else {
Node temp = this.top;
top = newNode;
top.next = temp;
length++;
}
}
public void pop() {
if (this.length == 0) return;
Node temp = this.top;
top = top.next;
temp.next = null;
length--;
}
public void printStack() {
Node current = this.top;
while (current != null) {
System.out.println(current.value);
current = current.next;
}
}
public boolean isEmpty() {
return length == 0;
}
}
public static void main(String[] args) {
Stack myStack = new Stack(1);
myStack.push(2);
myStack.push(3);
// myStack.printStack();
myStack.pop();
myStack.printStack();
}
public Stack sort(Stack stack) {
Stack tempStack = new Stack();
while (!stack.isEmpty()) {
Node temp = stack.top;
while (!tempStack.isEmpty()) {
if ( temp > tempStack.top) {
}
}
}
}
}