Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <string.h>
- struct Cvor;
- typedef struct Cvor *Position;
- struct Cvor {
- int el;
- Position next;
- };
- struct zadnji;
- typedef struct zadnji *Poslednji;
- struct zadnji
- {
- Position head;
- Position last;
- };
- Position noviClan(int );
- void dodajNaKraj(Position, int);
- void dodajNaPocetak(Position, int);
- void pop(Position);
- void push(Position);
- void ispisListe(Position p);
- void main() {
- struct Cvor head;
- head.next = NULL;
- int izbor;
- int el;
- printf("Izaberite 1 za stog, 2 za red, 0 za izlaz\n ");
- scanf(" %d", &izbor);
- switch (izbor)
- {
- case 1:
- printf(" STOG!!\n");
- printf(" Izaberite 1 dodavanje na stog, 2 za micanje sa stoga!!\n");
- scanf(" %d", &izbor);
- while (izbor != 3)
- {
- switch (izbor)
- {
- case 1:
- printf(" Unesite broj za unos u listu!\n");
- scanf(" %d", &el);
- dodajNaPocetak(&head,el);
- ispisListe(head.next);
- break;
- case 2:
- printf(" BRISEM PRVI CLAN!\n");
- pop(&head);
- break;
- }
- printf(" Izaberite 1 dodavanje na stog, 2 za micanje sa stoga, 3 za izlaz!!\n");
- scanf(" %d", &izbor);
- }
- break;
- case 2:
- printf(" RED!!");
- }
- }
- Position noviClan(int x) {
- Position novi = NULL;
- novi = (Position)malloc(sizeof(struct Cvor));
- novi->next = NULL;
- novi->el = x;
- }
- void dodajNaKraj(Position p, int x) {
- Position novi;
- while (p->next != NULL)
- {
- p = p->next;
- }
- novi = noviClan(x);
- p->next = novi;
- }
- void dodajNaPocetak(Position p, int x) {
- Position novi;
- novi = noviClan(x);
- novi->next = p->next;
- p->next = novi;
- }
- void pop(Position p){
- Position temp;
- temp = p->next;
- p->next = temp->next;
- free(temp);
- ispisListe(p->next);
- }
- void push(Position p) {
- Position last;
- last = p->next;
- }
- void ispisListe(Position p) {
- printf(" -----ISPIS LISTE-------\r\n");
- while (p != NULL)
- {
- printf("%d\n", p->el);
- p = p->next;
- }
- }
Add Comment
Please, Sign In to add comment