Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<conio.h>
- typedef enum { anuala, bianuala, perena }tip_planta;
- typedef enum {primavara,vara,toamna}perioada;
- typedef struct nod {
- char nume_planta[20];
- tip_planta tip;
- float pret;
- perioada inflorire;
- struct nod *st, *dr;
- }nod;
- nod *root = NULL;
- nod *adaugare(nod *t, char nume[20], tip_planta planta, float p, perioada per)
- {
- if (t == NULL)
- {
- t = (nod*)malloc(sizeof(nod));
- strcpy(t->nume_planta, nume);
- t->tip = planta;
- t->pret = p;
- t->inflorire = per;
- t->st = t->dr = NULL;
- }
- else if (strcmp(nume, t->nume_planta) < 0)
- t->st = adaugare(t->st, nume, planta, p, per);
- else
- if (strcmp(nume, t->nume_planta) > 0)
- t->dr = adaugare(t->dr, nume, planta, p, per);
- else
- printf("Nodul deja exista.");
- return t;
- }
- void afisare(nod *t)
- {
- if (t != NULL)
- {
- afisare(t->st);
- printf("\n%s %d %f %d", t->nume_planta, t->tip, t->pret, t->inflorire);
- afisare(t->dr);
- }
- }
- void citire()
- {
- FILE *f;
- char nume[20];
- tip_planta tp;
- float pre;
- perioada perin;
- f = fopen("plante.txt", "rt");
- if (f == NULL)
- printf("Fisirul nu se poate deschide.");
- else {
- while (!feof(f))
- {
- fscanf(f,"%s %d %f %d",nume, &tp, &pre, &perin);
- root = adaugare(root, nume, tp, pre, perin);
- }
- }
- }
- int main()
- {
- int opt;
- do {
- printf("\nMeniu:");
- printf("\n1.Citire");
- printf("\n2.Afisare");
- printf("Dati optiunea:");
- scanf("%d", &opt);
- switch (opt)
- {
- case 1:
- citire();
- break;
- case 2:
- afisare(root);
- break;
- case 0:
- break;
- }
- } while (opt != 0);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement