mihaispr
Administrator
 Inregistrat: acum 17 ani
Postari: 2142
|
|
//Concatenarea a 2 liste dublu inlantuite
#include <conio.h> #include <stdio.h> #include <alloc.h>
struct nod {int x; struct nod *next,*pred; }*l,*l1,*u;
int i,n;
struct nod* creare(struct nod *l,int k) {struct nod*aux; int v; printf("nr de noduri=" ); scanf("%d",&n); l=NULL; if(k==0) u=NULL; for (i=n;i>=1;i--) { aux= (struct nod*)malloc(sizeof(struct nod)); printf("\nInfo. nodului %d = ",i); scanf("%d",&v); aux->x=v; aux->next=l; aux->pred=NULL; if ((i==n)&&(k==0)) u=aux; if(l) l->pred=aux; l=aux; } return l; }
void afisare(struct nod*l) {struct nod*c; printf("\n" ); c=l; while (c) { printf("%d ",c->x); c=c->next; } }
struct nod* concat(struct nod* l,struct nod* l1) {struct nod* c,*aux; u->next=l1; l1->pred=u; return l; }
void main() {clrscr(); l=creare(l,0); afisare(l); l1=creare(l1,1); afisare(l1); printf("\nListele concatenate\n" ); l=concat(l,l1); afisare(l); getch(); }
|
|