Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*6. Napisati program koji pomoću vezanih listi simulira rad:
- a) stoga,
- b) reda.
- Napomena: Funkcija "push" sprema cijeli broj, slučajno generirani u opsegu od 10 -100*/
- #define _CRT_SECURE_NO_WARNINGS
- #define Lower 10
- #define Upper 100
- #include<stdio.h>
- #include<stdlib.h>
- #include<time.h>
- //Struktura
- struct node;
- typedef struct node* Pnode;
- struct node
- {
- int broj;
- Pnode Next;
- };
- //random
- int random()
- {
- int x = 0;
- srand((unsigned)time(0));
- x = (rand() % (Upper - Lower)) + Lower;
- return x;
- }
- //ClearScren
- /*void clrscr()
- {
- system("@cls||clear");
- }*/
- //Funkcije
- int push(Pnode);
- void meni();
- void print(Pnode);
- int main()
- {
- struct node Stack, Queue;
- Stack.Next= NULL;
- Queue.Next = NULL;
- int izbor = 0;
- do {
- meni();
- scanf(" %d", &izbor);
- switch (izbor)
- {
- case 1:
- push(&Stack);
- case 2:
- push(&Queue);
- case 5:
- print(Stack.Next);
- //case 7:
- //clrscr();
- }
- } while (izbor != 8);
- getchar();
- getchar();
- return 0;
- }
- int push(Pnode P)
- {
- Pnode q;
- q = (Pnode)malloc(sizeof(struct node));
- if (NULL == q)
- {
- printf("Greska kod alokacije memorije\n");
- return -1;
- }
- else
- {
- //Zavrsi ovo
- q->broj = random();
- q->Next = P->Next;
- P->Next = q;
- }
- return 1;
- }
- void meni()
- {
- printf("\nIzaberi sta oces:\n");
- printf("\nPush to stack: 1");
- printf("\nPush to queue: 2");
- printf("\n:Pop from stack: 3");
- printf("\nPop from queue: 4");
- printf("\nPrint Stack: 5");
- printf("\nPrint Queue: 6");
- printf("\nClearScreen 7");
- printf("\nExit: 8\n");
- printf("_________________________\n");
- return;
- }
- void print(Pnode P)
- {
- printf("\nIspis:\n ");
- while (P != NULL)
- {
- printf(" %d", P->broj);
- P = P->Next;
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement