fork download
  1. public class linkedStack<T>{
  2. private Node head=null;
  3.  
  4. public linkedStack(){
  5. }
  6.  
  7. void push(T item){
  8. if(head==null){
  9. head =new Node<T>();
  10. head.setValue(item);
  11. }else{
  12. Node oldHead=new Node<T>();
  13. oldHead=head;
  14. head.setValue(item);
  15. head.setNext(oldHead);
  16. }
  17. }
  18.  
  19. T pop() throws EmptyStackException{
  20. Node<T> thrown=head;
  21. head=head.getNext();
  22. return thrown.getValue();
  23. }
  24.  
  25. T top() throws EmptyStackException{
  26. Node<T> thrown=head;
  27. return thrown.getValue();
  28. }
  29.  
  30. boolean isEmpty(){
  31. return(head==null);
  32. }
  33. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1: error: expected unqualified-id before ‘public’
stdout
Standard output is empty