Guest User

Untitled

a guest
Dec 13th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. package com.tvidushi.stack.stack;
  2.  
  3. import com.tvidushi.stack.exception.StackOverFlowException;
  4. import com.tvidushi.stack.exception.StackUnderFlowException;
  5.  
  6.  
  7.  
  8.  
  9. public class StackLlistImpl<T> implements IStack{
  10. Node head;
  11.  
  12.  
  13. public StackLlistImpl(Node node) {
  14. this.head = node;
  15. }
  16.  
  17.  
  18.  
  19.  
  20. public void push(Object num) throws StackOverFlowException {
  21. if(head == null){
  22. head = new Node(num,null);
  23. return;
  24. }
  25. Node previous = head;
  26. head = new Node(num,previous);
  27.  
  28. }
  29.  
  30.  
  31.  
  32.  
  33. public T peek() throws StackUnderFlowException {
  34. if(head == null) throw new StackUnderFlowException("Stack is empty ");
  35. return (T) head.data;
  36. }
  37.  
  38.  
  39. public T pop() throws StackUnderFlowException {
  40. if(isEmpty()) throw new StackUnderFlowException("") ;
  41. T value = (T) head.data;
  42. head = head.next;
  43. return value;
  44. }
  45.  
  46. public boolean isEmpty() {
  47.  
  48. return false;
  49. }
  50.  
  51.  
  52.  
  53.  
  54. public boolean isFull() {
  55.  
  56. return false;
  57. }
  58.  
  59.  
  60.  
  61. public static class Node<T> {
  62.  
  63. Node next;
  64. T data;
  65.  
  66. public Node(T data, Node node){
  67. this.next = node;
  68. this.data = data;
  69. }
  70. }
  71.  
  72.  
  73. }
Add Comment
Please, Sign In to add comment