Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <stdio.h>
- # include <stdlib.h>
- typedef struct stos{
- int wart;
- struct stos *poprzedni;
- struct stos *nastepny;
- }stos;
- void push (stos **head, stos **tail,int liczba)
- {
- stos *nowy;
- nowy = (stos *)malloc(sizeof(stos));
- nowy->wart = liczba;
- nowy->poprzedni=NULL;
- nowy->nastepny = NULL;
- if(*head == NULL){
- *head = nowy;
- *tail = nowy;
- //printf("!");
- }
- else {
- nowy->poprzedni=*tail;
- (*tail)->nastepny = nowy;
- (*tail)=nowy;
- }
- }
- int pop(stos **head)
- {
- stos *tmp=(*head);
- int liczba=0;
- if (*head ==NULL)
- printf("Stos pusty");
- else if ((*head)->nastepny==NULL) {
- *head=NULL;
- liczba = tmp->wart;
- }
- else{
- (*head) =(*head)->nastepny;
- liczba =tmp->wart;
- free(tmp);
- }
- return liczba;
- }
- void show(stos *head)
- {
- while (head!=NULL){
- printf("%d\n",
- head->wart);
- head=head->nastepny; }
- }
- int main ()
- {
- int liczba, option=0;
- stos *head = NULL, *tmp = NULL;
- stos *tail = NULL;
- while(option!=4)
- {
- printf("\n1.Push\n2.Show\n3.Pop\n4.END\n");
- scanf("%d",&option);
- switch(option)
- {
- case 1: printf("Podaj wartosc: ");
- scanf("%d", &liczba);
- push(&head,&tail,liczba);break;
- case 2: printf("Wyswetlam stos od gory: \n");
- show(head); break;
- case 3: printf("Usuwanie ze stosu: ");
- printf("%d", pop(&head));break;
- case 4: option = 4;break;
- default: break;
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement