document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6.  
  7. class lista{
  8.     private:
  9.     int key;
  10.     lista *next;
  11.     public:
  12.     void push(class lista *head, int x);
  13.     void wypisz(class lista *head);
  14. }*head=NULL,*tmp=NULL;   // tmp=ogon
  15.  
  16. void lista:: push(class lista *head,int x)
  17. {
  18.   if(tmp==NULL)
  19.   {
  20.       head->key=x;
  21.       head->next=NULL;
  22.       tmp=head;
  23.   }else{
  24.         head=(class lista*)new lista;
  25.         head->key=x;
  26.         head->next=NULL;
  27.         tmp->next=head;
  28.         tmp=head;
  29.   }
  30.  
  31.  
  32.  
  33. }
  34.  
  35. void lista::wypisz(class lista *head){
  36.  
  37.  
  38.     while(head)
  39.     {
  40.         cout<< "Wartosc:  "<<head->key <<" Adres " <<head; // wypisuje wartość i adres
  41.  
  42.        
  43.         cout<< "\\n\\n";
  44.         head=head->next;
  45.     }
  46. }
  47.  
  48.  
  49.  
  50.  
  51. int main(){
  52.  
  53.    
  54.     int n;
  55.     cout << "Ile liczb \\n\\n";
  56.     cin >>n;
  57.  
  58.  
  59.     head=(class lista*)new lista;
  60.  
  61.     for(int i=0;i<n;i++){
  62.        head->push(head,i); // lub   (*head).push(head,x);
  63.  
  64.     }
  65. cout << "\\n\\n\\n";
  66.  
  67. head->wypisz(head);
  68.  
  69. }
');