Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. # include "stack.h"
  2. # include <iostream>
  3.  
  4. void push(list *userList, int numToAdd)
  5. {
  6. list *first = NULL;
  7.  
  8. if (userList->next == NULL)
  9. {
  10. userList->num = numToAdd;
  11. //return(userList);
  12. }
  13.  
  14. else
  15. {
  16. std::cout << "before" << userList << std::endl;
  17. first = new list;
  18. first->next = userList;
  19. first->num = numToAdd;
  20.  
  21. userList = first;
  22. //return(first);
  23. }
  24. }
  25.  
  26. int pop(list *userList)
  27. {
  28. list *curr = userList->next;
  29. int numToReturn = userList->num;
  30.  
  31. if (numToReturn !=NULL)
  32. {
  33. std::cout << numToReturn << std::endl; // this line is for testing, to print the numbers to the screen
  34.  
  35. delete userList;
  36. userList = curr;
  37.  
  38. return(numToReturn);
  39. }
  40.  
  41. else
  42. {
  43. delete userList;
  44. std::cout << "NULL" << std::endl; // this line is for testing, to print the numbers to the screen
  45. return(NULL);
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement