Revision: 63659
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at May 27, 2013 01:52 by cristy1126
Initial Code
#include <stdio.h> #include <malloc.h> #include <stdlib.h> //implementare stiva struct numar{ int valoare; struct numar *next; }; struct numar *prim = NULL; int nr_elem; struct numar *creare(int val){ struct numar *ptr = (struct numar*)malloc(sizeof(struct numar)); if(NULL == ptr){ printf("\nNu s-a putut crea nodul\n"); return NULL; } ptr->valoare = val; ptr->next = NULL; prim = ptr; nr_elem = 1; return ptr; } //functie afisare stiva void afisare_coada(){ struct numar *ptr = prim; printf("\nInceput coada"); while(ptr != NULL){ printf("\n %d \n", ptr->valoare); ptr = ptr->next; } printf("\nSfarsit coada"); } //functie adaugare in stiva push struct numar *push(val){ struct numar *ptr = (struct numar*)malloc(sizeof(struct numar)); ptr->valoare = val; ptr->next = NULL; if(NULL == prim){ creare(val); }else{ ptr->next = prim; prim = ptr; nr_elem++; } afisare_coada(); return ptr; } //functie pop int pop(){ struct numar *pop = prim; struct numar *temp = NULL; if(pop != NULL){ prim = prim->next; } free(pop); pop = NULL; afisare_coada(); return 1; } //functie empty int empty(){ struct numar *ptr = prim; while(ptr != NULL){ pop(); afisare_coada(); } return 1; } int main(){ int i; for (i = 5; i>0; i--){ push(i); } pop(); getch(); }
Initial URL
http://ssm-iscri.ro
Initial Description
stiva
Initial Title
STIVA - implementare cu lista inlantuita
Initial Tags
Initial Language
C