Advertisement
BowserFlash13

Sort?

May 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 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) {
  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.  
  35.     for (int i = 0; i < n - 1; i++) {
  36.         for (int j = 0; j < n - i - 1; j++) {
  37.             if (trenutni->podatak > trenutni->next->podatak) {
  38.                 cout << "Debug?";
  39.                 swap(trenutni->podatak, trenutni->next->podatak);
  40.             }
  41.         }
  42.     }
  43.  
  44. }
  45.  
  46. void ispis() {
  47.     cvor *trenutni;
  48.     trenutni = glava;
  49.  
  50.     while(trenutni != NULL) {
  51.         cout << trenutni->podatak<< "   ";
  52.         trenutni = trenutni->next;
  53.     }  
  54. }
  55.  
  56. void brisi() {
  57.     cvor*trenutni;
  58.     while (glava != NULL) {
  59.         trenutni = glava;
  60.         glava = glava->next;
  61.         delete trenutni;
  62.     }
  63. }
  64.  
  65. void izbroj() {
  66.     cvor *trenutni;
  67.     trenutni = glava;
  68.  
  69.     //while(trenutni != NULL) {
  70.     for (int i = 0; i < 10; i++) {
  71.         trenutni = trenutni->next;
  72.     }
  73. }
  74.  
  75. int main() {
  76.     int n = 0;
  77.     cout << "Upis  " << endl;
  78.     upis(5, n);
  79.     upis(12, n);
  80.     upis(3, n);
  81.     upis(1, n);
  82.     ispis();
  83.     system("pause");
  84.  
  85.    
  86.     return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement