Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. struct element
  8. {
  9. string dane;
  10. element *nast;
  11. };
  12.  
  13. element *wierzch = NULL;
  14.  
  15. void push(string nowedane)
  16. {
  17.  
  18. element *punkt;
  19. punkt = wierzch;
  20. wierzch = new element;
  21. wierzch->dane = nowedane;
  22. wierzch->nast = punkt;
  23. }
  24. string pop()
  25. {
  26. string x;
  27. element *punkt;
  28. if(wierzch != NULL)
  29. {
  30. x = wierzch->dane;
  31. punkt = wierzch->nast;
  32. delete wierzch;
  33. wierzch = punkt;
  34. }
  35. return x;
  36. }
  37. bool empty()
  38. {
  39. if(wierzch == NULL)
  40. return true;
  41. else return false;
  42. }
  43.  
  44. int main()
  45. {
  46. string linia;
  47. getline(cin, linia);
  48.  
  49. while(linia != "KONIEC"){
  50. push(linia);
  51. getline(cin, linia);
  52. }
  53.  
  54. while(!empty()){
  55. cout << pop() << endl;
  56. }
  57.  
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement