Advertisement
Guest User

javaTC2015

a guest
May 27th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. /**
  2. * Class that implements a stack of integers
  3. * by a linked list of integers.
  4. */
  5. public class StackByLinkedList implements Stack {
  6.  
  7. /** head node of the linked list */
  8. LinkedListNode myHead;
  9.  
  10. /**
  11. * Check if the list is empty
  12. * @return 'true' if empty, 'false' otherwise
  13. */
  14. public boolean empty(){
  15. return (myHead == null);
  16. }
  17.  
  18. /**
  19. * Get the value that is on the top of the stack
  20. * @return the top value
  21. */
  22. public int top(){
  23. return myHead.value();
  24. }
  25.  
  26. /**
  27. * Add a value at the top of the stack
  28. * @param aValue new value
  29. */
  30. public void push(int aValue){
  31. LinkedListNode temp = new LinkedListNode(aValue, myHead);
  32. myHead = temp;
  33. }
  34.  
  35. /**
  36. * Remove the value that is on the top of the stack
  37. */
  38. public void pop(){
  39. myHead = myHead.next();
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement