0% found this document useful (0 votes)
101 views1 page

Examen Sda

1. The document contains C++ code definitions for functions to create and manipulate a stack data structure of wagon node objects. 2. It includes functions to read input, load node data, add nodes to the stack, and remove nodes from the stack. 3. The main function creates an empty stack, adds nodes by calling the add function until it fails, then prints the nodes in reverse order by repeatedly removing the top node from the stack.

Uploaded by

Nicoleta Dobre
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views1 page

Examen Sda

1. The document contains C++ code definitions for functions to create and manipulate a stack data structure of wagon node objects. 2. It includes functions to read input, load node data, add nodes to the stack, and remove nodes from the stack. 3. The main function creates an empty stack, adds nodes by calling the add function until it fails, then prints the nodes in reverse order by repeatedly removing the top node from the stack.

Uploaded by

Nicoleta Dobre
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

STIVE 1.

Afisare: int pcit_int(char text[], int


*x) {char t[255];for( ; ; ){printf(text);if(gets(t) == NULL) return 0;if(sscanf(t,"%d",x) == 1)return 1;}} 2.Citire: int pcit_int_lim(char text[], int inf, int sup, int *pint) {for( ; ; ){ if(pcit_int(text, pint) == 0)return 0; if(*pint >= inf && *pint <= sup) return 1;printf("\nIntregul tastat nu apartine intervalului:"); printf("[%d,%d]\n", inf, sup); printf("Se reia citirea\n");}} 3.Incarcare: int incnod(TNOD *p) { char t[255];char er[] = "S-a tastat EOF in pozitie rea\n";long cod; int icod; for( ; ; ){printf("cod vagon: ");if(gets(t) == 0)return -1; if(sscanf(t, "%ld", &cod) == 1 && cod >= 0 && cod <= 999999999) break;printf("cod vagon eronat\n");} p -> cvag = cod; for( ; ; ){printf("cod marfa: ");if(gets(t) == 0){printf(er); return 0;} if(sscanf(t, "%ld", &cod) == 1 && cod >= 0 && cod <= 999999999) break;printf("cod marfa eronat\n"); }p -> cmarfa = cod; if(pcit_int_lim("cod expeditor: ", 0, 9999, &icod) == 0){printf(er);return 0;}p -> exp = icod; if(pcit_int_lim("cod destinatar: ", 0, 9999, &icod) == 0){printf(er); return 0;}p -> dest = icod; return 1;} 4.Eliberare: void elibnod(TNOD *p) 5.Inserare: TNOD *iniprim(){ extern TNOD *prim, *ultim;

TNOD *p;int n; n = sizeof(TNOD); if(((p = (TNOD *)malloc(n)) != 0) && (incnod(p) == 1)){if(prim == 0){ prim = ultim = p;p -> urm = 0;} else{p -> urm = prim;prim = p;} return p;}if(p == 0){printf("memorie insuficienta\n");exit(1);}elibnod(p); return 0;} 6.Stergere: void spn(){extern TNOD *prim, *ultim;TNOD *p; if(prim == 0)return ;p = prim; prim = prim -> urm;elibnod(p); if(prim == 0)ultim = 0;} 7. Sa se scrie un program care creaza o stiva, apeland functia iniprim, pana cand aceasta returneaza valoarea zero, apoi listeaza inventarul vagoanelor in ordinea inversa citirii lor. # include <stdio.h># include <conio.h># include <alloc.h> # include <stdlib.h>typedef struct tnod{long cvag;long cmarfa;int exp; int dest;struct tnod *urm;} TNOD; # include "pcit_int.cpp" # include "p_i_l.cpp" # include "incnod.cpp" # include "elibnod.cpp"# include "iniprim.cpp"# include "spn.cpp" TNOD *prim, *ultim;main(){ prim = ultim = 0; while(iniprim() != 0); while(prim != 0){printf("\ncod vagon: %ld\tcontinut: %ld\n", prim > cvag, prim -> cmarfa); printf("expeditor: %d\tdestinatar: %d\n", prim -> exp, prim -> dest); spn();}getch();}

You might also like