Tardeli

Untitled

Nov 13th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.99 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <string.h>
  6.  
  7.  
  8. struct Cvor;
  9. typedef struct Cvor *Position;
  10.  
  11. struct Cvor {
  12.     int el;
  13.     Position next;
  14. };
  15. struct zadnji;
  16. typedef struct zadnji *Poslednji;
  17. struct zadnji
  18. {
  19.     Position head;
  20.     Position last;
  21. };
  22. Position noviClan(int );
  23. void dodajNaKraj(Position, int);
  24. void dodajNaPocetak(Position, int);
  25. void pop(Position);
  26. void push(Position);
  27. void ispisListe(Position p);
  28. void main() {
  29.     struct Cvor head;
  30.     head.next = NULL;
  31.     int izbor;
  32.     int el;
  33.     printf("Izaberite 1 za stog, 2 za red, 0 za izlaz\n ");
  34.     scanf(" %d", &izbor);
  35.     switch (izbor)
  36.     {
  37.     case 1:
  38.         printf(" STOG!!\n");
  39.         printf(" Izaberite 1 dodavanje na stog, 2 za micanje sa stoga!!\n");
  40.         scanf(" %d", &izbor);
  41.         while (izbor != 3)
  42.         {
  43.             switch (izbor)
  44.             {
  45.             case 1:
  46.                 printf(" Unesite broj za unos u listu!\n");
  47.                 scanf(" %d", &el);
  48.                 dodajNaPocetak(&head,el);
  49.                 ispisListe(head.next);
  50.  
  51.                 break;
  52.             case 2:
  53.                 printf(" BRISEM PRVI CLAN!\n");
  54.                 pop(&head);
  55.                
  56.                
  57.                 break;
  58.            
  59.                
  60.             }
  61.             printf(" Izaberite 1 dodavanje na stog, 2 za micanje sa stoga, 3 za izlaz!!\n");
  62.             scanf(" %d", &izbor);
  63.         }
  64.         break;
  65.     case 2:
  66.         printf(" RED!!");
  67.  
  68.     }
  69.  
  70. }
  71. Position noviClan(int x) {
  72.     Position novi = NULL;
  73.     novi = (Position)malloc(sizeof(struct Cvor));
  74.     novi->next = NULL;
  75.     novi->el = x;
  76. }
  77. void dodajNaKraj(Position p, int x) {
  78.     Position novi;
  79.     while (p->next != NULL)
  80.     {
  81.         p = p->next;
  82.     }
  83.     novi = noviClan(x);
  84.     p->next = novi;
  85. }
  86. void dodajNaPocetak(Position p, int x) {
  87.     Position novi;
  88.     novi = noviClan(x);
  89.     novi->next = p->next;
  90.     p->next = novi;
  91. }
  92. void pop(Position p){
  93.     Position temp;
  94.  
  95.     temp = p->next;
  96.     p->next = temp->next;
  97.  
  98.     free(temp);
  99.     ispisListe(p->next);
  100. }
  101. void push(Position p) {
  102.     Position last;
  103.     last = p->next;
  104.  
  105. }
  106. void ispisListe(Position p) {
  107.     printf(" -----ISPIS LISTE-------\r\n");
  108.     while (p != NULL)
  109.     {
  110.         printf("%d\n", p->el);
  111.         p = p->next;
  112.     }
  113. }
Add Comment
Please, Sign In to add comment