Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- typedef struct _cvor* Position;
- typedef struct _cvor
- {
- int broj;
- Position next;
- Position last;
- }Cvor;
- int Push(Position);
- int Pop(Position);
- int Ispis(Position);
- Position GenerirajClan(int);
- int DodajNaPocetak(Position, Position);
- int main()
- {
- Cvor niz;
- int unos = 0;
- srand((unsigned)time(NULL));
- niz.next = NULL;
- while (unos != 4)
- {
- printf("Unesite 1 za push, 2 za pop, 3 za ispis liste, 4 za prekid: ");
- scanf(" %d", &unos);
- if (unos == 1)
- Push(&niz);
- else if (unos == 2)
- Pop(&niz);
- else if (unos == 3)
- Ispis(niz.next);
- else if (unos != 4)
- printf("Pogresan unos!\n");
- }
- return 0;
- }
- int Push(Position head)
- {
- int temp;
- temp = rand() % (100 - 10 + 1) + 10;
- DodajNaPocetak(head, GenerirajClan(temp));
- return 0;
- }
- int Pop(Position head)
- {
- while(head->next->next != NULL)
- {
- head = head->next;
- }
- head->next = NULL;
- return 0;
- }
- Position GenerirajClan(int broj)
- {
- Position noviCvor;
- noviCvor = (Position)malloc(sizeof(Cvor));
- noviCvor->broj = broj;
- noviCvor->next = NULL;
- return noviCvor;
- }
- int DodajNaPocetak(Position head, Position novi)
- {
- novi->next = head->next;
- head->next = novi;
- return 0;
- }
- Ispis(Position position)
- {
- while (position != NULL)
- {
- printf("%d ", position->broj);
- position = position->next;
- }
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement