hmmm...kurde nie kapuje. Poprawiłem co trzeba i funkcja już się nie wysypuje ale nie działa tak jak powinna. Wkleję całość, żeby było widać jak to wygląda.
Kod: Zaznacz cały
#include <stdio.h>
#include <stdlib.h>
typedef struct lista{
int x;
struct lista * next;
} element;
element * dodajliczbe(element * head, int a, int b, int n);
element * usun ( element * head);
void wypisz ( element * head );
int main(int argc, char *argv[])
{
element * head=NULL;
dodajliczbe (head, 0, 10, 10);;
usun(head);
wypisz (head);
system("PAUSE");
return 0;
}
element * dodajliczbe (element * head, int a, int b, int n){
int x;
element * wsk=NULL;
wsk=(element*)malloc(sizeof(element));
int i;
for(i=0; i<n; i++){
if(head==NULL){
x=rand()%(b-a+1)+ a;
wsk->x=x;
printf("%d
", wsk->x);
}
else{
x=rand()%(b-a+1)+ a;
wsk->x=x;
wsk->next=head;
printf("%d
", wsk->x);
head=wsk;
}
} printf("
druga funkcja
");
return head;
}
element * usun ( element * head){
if (head != NULL){
element * tmp1=head;
element * tmp2=head->next;
element * tmp3=tmp2;
for( ;tmp1->next!=NULL; tmp1=tmp1->next){
for( ;tmp2->next!=NULL; tmp2=tmp2->next){
tmp3=tmp2;
if(tmp1->x == tmp2->x){
tmp3=tmp3->next;
free(tmp2);
tmp2=tmp3;
}}}}
return head;
}
void wypisz ( element * head ){
element * tmp=head;
while(tmp!=NULL){
printf("%d ", tmp->x);
tmp=tmp->next;
}
}