SHARE
TWEET

Untitled

a guest Dec 5th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. struct TDATA
  7. {  
  8.     int number;
  9.     struct TDATA *next;
  10. };
  11.  
  12. TDATA* addStack(TDATA* p, int liczba)
  13. {
  14.     if (p == NULL)
  15.     { //tworzymy nowy stos
  16.         p = new TDATA;
  17.         p->number = liczba;
  18.         (*p).next = NULL;
  19.     }
  20.     else
  21.     { //stos juz istnieje
  22.         TDATA* tmp = p;
  23.         p = new TDATA;
  24.         p->number = liczba;
  25.         (*p).next = tmp;
  26.     }
  27.     return p;
  28. }
  29.  
  30. int getStack(TDATA*& p)
  31. {
  32.     int tmp_number;
  33.     if (p!=NULL)
  34.     {
  35.         tmp_number = (p)->number; //(*p).number
  36.         TDATA* tmp_next = ((*p)).next;
  37.         delete p;
  38.         p = tmp_next;
  39.     }
  40.     return tmp_number;
  41. }
  42.  
  43. void peek(TDATA* p)
  44. {
  45.     cout<<p->number<<endl;
  46.     return;
  47. }
  48.  
  49. void printStack(TDATA* p)
  50. {
  51.     while(p!=NULL)
  52.     {
  53.         cout<<p->number<<endl;
  54.         p = p->next;
  55.     }
  56.     return;
  57. }
  58.  
  59. int main()
  60. {
  61.     TDATA* stack = NULL;
  62.     stack=addStack(stack, 1);
  63.     stack=addStack(stack, 2);
  64.     stack=addStack(stack, 3);
  65.     stack=addStack(stack, 4);
  66.         getStack(stack);
  67.         getStack(stack);
  68.     stack=addStack(stack, 5);
  69.     stack=addStack(stack, 6);
  70.     printStack(stack);
  71.    
  72.     getchar();
  73.     return 0;
  74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top