SHARE
TWEET

Sortirana vezana lista

a guest Sep 11th, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5.  
  6.  
  7. struct node{
  8.     int value;
  9.     node *next;
  10. };
  11.  
  12. typedef node *lista;
  13.  
  14. int main(){
  15.    
  16.     lista pointer = new node;
  17.     pointer->next = NULL;
  18.        
  19.     srand(time(NULL));
  20.    
  21.     // UPISIVANJE U LISTU
  22.     int a,i,z;
  23.         do{
  24.             cout << "Koliko random brojeva? ";
  25.             cin >> a;
  26.         } while(a<0);
  27.    
  28.     if(a>0){
  29.     for(i=0;i<a;i++){
  30.         z = rand();
  31.         lista el = pointer;
  32.         while(el->next != NULL && el->next->value<z){
  33.             el = el->next;
  34.         }
  35.         lista novi = new node;
  36.         novi->value = z;
  37.         novi->next = el->next;
  38.         el->next = novi;
  39.         }
  40.     }  
  41.     // BRISANJE IZ LISTE
  42.     while(pointer->next != NULL){
  43.         node *el;
  44.         cout << pointer->next->value << " ";
  45.         el = pointer;
  46.         pointer = pointer->next;
  47.         delete el;
  48.        
  49.     }
  50.  
  51.    
  52.    
  53.    
  54.     return 0;
  55. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top