Operatii Asupra Listei Liniare Simplu Inlantuit2

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

/* Operatii asupra Listei Liniare Simplu Inlantuite */

#include <stdio.h>

#include <conio.h>

#include <ctype.h>

#include <alloc.h>

#include <string.h>

struct NOD

int cheie;

char info[10];

struct NOD *urm;

};

typedef struct NOD Tnod;

typedef Tnod *ref;

ref prim;

ref q,r;

void ins_prim(void)

q=malloc(sizeof(Tnod));

printf("Introduceti cheia: ");

scanf("%d",&q);

printf("Introduceti informatia: ");

fflush(stdin); scanf("%s",q->info);
q->urm=NULL;

prim=q;

} /* ins_prim */

void ins_cs(void) /* Insereaza un NOD in spatele listei */

r=malloc(sizeof(Tnod));

printf("Introduceti cheia: ");

scanf("%d",&r->cheie);

printf("Introduceti informatia: ");

fflush(stdin); scanf("%s",r->info);

r->urm=NULL;

q->urm=r;

q=r;

} /* ins_cs */

void listare(void)

if(prim == NULL)

printf("Lista este vida !!! \n");

else

clrscr();

printf("\nElementele listei sunt : ");

r=prim;

while(r!=NULL)

{
printf("\nCheia : %d", r->cheie);

printf("\nInformatia: %s", r->info);

r=r->urm;

} /* Listare */

void creare(void)

char c;

prim=NULL;

ins_prim();

while(c=='D')

ins_cs();

listare();

printf("Continuati ?! [D/N] : ");

fflush(stdin); scanf("%c",&c); c=toupper(c);

}/* Creare */

void main(void)

char op;

char c;

prim=NULL;

clrscr();
do

clrscr();

printf("\t\tOperatii asupra Listei Liniare Simplu Inlantuite\n\n");

printf("C - Crearea listei.\n");

printf("V - Crearea primului NOD. \n");

printf("A - Adaugare la sfarsitul listei.\n");

printf("L - Listare. \n");

printf("E - Exit !! \n");

printf("\n\tIntroduceti optiunea : ");

fflush(stdin);scanf("%s",&op); op=toupper(op);

printf("\n");

switch(op)

case 'V': ins_prim();

break;

case 'C': creare();

break;

case 'A': ins_cs();

listare();

break;

case 'L': listare();

break;

case 'E': break;

default : printf("Optiunea e gresita!\n");

getch();

break;
}

}while(op!='E');

} /* MAIN */

You might also like