Trying the question, the algorithm to build a stack using linked list is at the end. hope it could help
a linked list has:
1. properties:
a. Node start
b. Node prev
c. Node current
2. methods:
a. add_before_current(object x)
b. current()
c. remove()
.....
for example
1. building the linked list
add_before_current("1")
add_before_current("2")
add_before_current("3")
//the linked list should be 3->2->1
//the current is pointing to "3"
2. obtaining the current node
current()
3. removing the current node
remove() //obtain "3"
remove() //obtain "2"
remove() //obtain "1"
//end
remark: a stack is a data structure which is "First In Last Out"
implementing the stack:
1. properties:
a. Node topofStack
.....
2. methods:
a. push(object x){
add_before_current(x);
}
b. pop(
current();
topofStack=remove();
)
a linked list has:
1. properties:
a. Node start
b. Node prev
c. Node current
2. methods:
a. add_before_current(object x)
b. current()
c. remove()
.....
for example
1. building the linked list
add_before_current("1")
add_before_current("2")
add_before_current("3")
//the linked list should be 3->2->1
//the current is pointing to "3"
2. obtaining the current node
current()
3. removing the current node
remove() //obtain "3"
remove() //obtain "2"
remove() //obtain "1"
//end
remark: a stack is a data structure which is "First In Last Out"
implementing the stack:
1. properties:
a. Node topofStack
.....
2. methods:
a. push(object x){
add_before_current(x);
}
b. pop(
current();
topofStack=remove();
)