Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- struct node{
- int value;
- node *next;
- };
- typedef node *lista;
- int main(){
- lista pointer = new node;
- pointer->next = NULL;
- srand(time(NULL));
- // UPISIVANJE U LISTU
- int a,i,z;
- do{
- cout << "Koliko random brojeva? ";
- cin >> a;
- } while(a<0);
- if(a>0){
- for(i=0;i<a;i++){
- z = rand();
- lista el = pointer;
- while(el->next != NULL && el->next->value<z){
- el = el->next;
- }
- lista novi = new node;
- novi->value = z;
- novi->next = el->next;
- el->next = novi;
- }
- }
- // BRISANJE IZ LISTE
- while(pointer->next != NULL){
- node *el;
- cout << pointer->next->value << " ";
- el = pointer;
- pointer = pointer->next;
- delete el;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement