Advertisement
BowserFlash13

dsaads

May 20th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6.  
  7.  
  8. struct cvor {
  9.     int podatak;
  10.     cvor *next;
  11. };
  12.  
  13. cvor *glava;
  14.  
  15. void upis(int a, int &n) {
  16.     n++;
  17.     cvor *novi = new cvor;
  18.     novi->podatak = a;
  19.     novi->next = NULL;
  20.  
  21.     if (glava == NULL) {
  22.         glava = novi;
  23.     }
  24.     else {
  25.         cvor*trenutni;
  26.         trenutni = glava;
  27.         while (trenutni->next != NULL) {
  28.             trenutni = trenutni->next;
  29.          }
  30.         trenutni->next = novi;
  31.     }
  32.     cvor*trenutni;
  33.     trenutni = glava;
  34.     for (int i = 0; i < n - 1; i++) {
  35.         for (int j = 0; j < n - i - 1; j++) {
  36.             if (trenutni->podatak > trenutni->next->podatak) {
  37.                 swap(trenutni->podatak, trenutni->next->podatak);
  38.             }
  39.         }
  40.     }
  41.  
  42. }
  43.  
  44. void ispis() {
  45.     cvor *trenutni;
  46.     trenutni = glava;
  47.  
  48.     while(trenutni != NULL) {
  49.         cout << trenutni->podatak<< "   ";
  50.         trenutni = trenutni->next;
  51.     }  
  52. }
  53.  
  54. void brisi() {
  55.     cvor*trenutni;
  56.     while (glava != NULL) {
  57.         trenutni = glava;
  58.         glava = glava->next;
  59.         delete trenutni;
  60.     }
  61. }
  62.  
  63. void izbroj() {
  64.     cvor *trenutni;
  65.     trenutni = glava;
  66.  
  67.     //while(trenutni != NULL) {
  68.     for (int i = 0; i < 10; i++) {
  69.         trenutni = trenutni->next;
  70.     }
  71. }
  72.  
  73. int main() {
  74.     int n = 0;
  75.     cout << "Upis  " << endl;
  76.     upis(5, n);
  77.     upis(12, n);
  78.     upis(3, n);
  79.     upis(1, n);
  80.     ispis();
  81.     system("pause");
  82.  
  83.    
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement