[ Vojkan123 @ 26.05.2014. 22:21 ] @
Program treba da zadati broj iz liste duplira Ulaz: 2->7->8->9 broj:7 Izlaz: 2->7->7->8->9 Ne znam gde gresim,ako neko moze da pomogne hvala unapred ovo je moj kod: Code: #include<stdio.h> #include<stdlib.h> typedef struct cvor{ int broj; struct cvor* sledeci; }Cvor; Cvor* napravi_cvor(int x){ Cvor *novi=(Cvor*)malloc(sizeof(Cvor)); if(novi==NULL){ fprintf(stderr,"malloc \n"); exit(1); } novi->broj=x; novi->sledeci=NULL; return novi; } Cvor* dodaj_na_pocetak(Cvor* lista,int x){ Cvor* novi=napravi_cvor(x); novi->sledeci=lista; return novi; } void ispisi_listu(Cvor* lista){ for(;lista!=NULL;lista=lista->sledeci) printf("%d",lista->broj); putchar('\n'); } void Push(Cvor ** lista,int broj){ Cvor* novi=(Cvor*)malloc(sizeof(Cvor)); if(novi==NULL) return; novi->broj=broj; novi->sledeci=*lista; *lista=novi; } void udvoji(Cvor ** lista,int data){ if(*lista==NULL) return; Cvor *tekuci=*lista; for(;tekuci;tekuci=tekuci->sledeci){ if(tekuci->broj==data) Push(&(tekuci->sledeci),data); } } int main(){ Cvor *lista=NULL; int x,data; while(1){ scanf("%d",&x); if(x==0) break; lista=dodaj_na_pocetak(lista,x); } putchar('\n'); ispisi_listu(lista); putchar('\n'); udvoji(&lista,2); ispisi_listu(lista); return 0; } |