Stack Implementations
Using Linked Lists
public class LinkedListOfStrings {
private node head = null ;
// Inner class
private class Node
{
String item;
Node next;
}
public boolean isEmpty {
return head == null;
}
public void push(String item) {
Node oldNode = head;
Node newNode = null;
newNode.item = item;
item.next = oldNode;
}
public String pop(){
String item = head.item;
head = head.next;
return item;
}
}Memory Calculation for Node
Using Array - Fixed size
Using Array - dynamic size
Generic Stack Linked List Implementation
Generic Stack Array Implementation
Stack Iteration
Trade offs
Linked List Implementation:
Resizing-array implementation:
Last updated