Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct stos{
- int element;
- struct stos *wskaznik;
- };
- struct stos *nowy, *stary;
- void push(int n){
- stary = nowy;
- nowy = malloc(sizeof (struct stos));
- nowy->element = n;
- nowy -> wskaznik = stary;
- }
- void pop (void){
- if(nowy -> element != NULL){
- stary = nowy -> wskaznik;
- printf ("usunales %d \n\n\n\n",nowy ->element);
- free(nowy -> wskaznik);
- nowy = stary;
- }
- }
- int main()
- {
- int n;
- int k;
- while (k!= 4){
- printf("kolejka LIFO");
- printf("\n \n \t \t \t =====CO CHCESZ ZROBIC?=====");
- printf("\n \n \t 1. Wydrukuj oststni element");
- printf("\n\n\t 2. Dodaj element");
- printf ("\n\n\t 3. Zdejmij ostatni element");
- printf ("\n\n\t 4. Zakoncz program\n\n");
- scanf ("%d",&k);
- switch(k){
- case 1 :
- {
- printf("%d",nowy->element);
- }break;
- case 2:
- {
- printf("jaka liczbe chcesz dodac?");
- scanf ("%d",&n);
- push(n);
- printf ("pomyslnie dodano %d na stosn\n\n\n\n",n);
- }break;
- case 3:
- {
- pop();
- }break;
- };}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement