Δημοσιεύτηκε: 05 Ιούλ 2011, 22:06
Λοιπον εχω 2 αποριουλες ...
Καταρχην γιατι δεν μου δουλευει η συναρτηση???? :/
Κατα δευτερον εχουμε πει πως ο δεικτης head εδω (list) στους κωδικες του migf1 δεν ειναι ο ιδιος κομβος
αλλα ειναι ενας δεικτης που δειχνει σε εναν κομβο... ωραια τοτε αυτο εδω γιατι
head->next=one;
εχει πεδιο next???
- Κώδικας: Επιλογή όλων
/*==========================================================
YLOPOIHSH LISTAS ME SUNARTHSEIS
5/7/11
==========================================================
*/
#include<stdio.h>
#include<stdlib.h>
typedef struct customer /*xreiazetai kai i leksi customer wste na kserei mesa sto swma
tou se ti tupo anaferetai o deiktis next */
{
int id;
struct customer *next;
} Customer;
int main ()
{
int i;
Customer *head , *one;
Customer *two;
head = NULL;
{
head= calloc(1,sizeof(Customer));
head->id=1;
head->next = NULL;
}
one= calloc(1,sizeof(Customer));
one->id=2;
one->next=NULL;
head->next=one;
two=calloc(1,sizeof(Customer));
two->id=3;
two->next=NULL;
one->next=two;
for(i=0; i<3; i++)
{
void list_print(Customer *head);
}
free(one->next); /*Etsi einai to swsto kai oxi opws to eixa anapoda gt einai sfalma */
free(head->next); /* epeidi to head itan hdh katestrameno dn borousa meta na dwsw px */
free(head); /* free(head->next) */
if(head==NULL)
printf("H free dn ekane kala tin douleia tis \n");
else
printf("H mnimi eleutherwthike!");
return 0;
}
void list_print(Customer *head)
{
while(head)
{
printf("%d",head->id);
head=head->next;
}
putchar('\n');
return;
}
Καταρχην γιατι δεν μου δουλευει η συναρτηση???? :/
Κατα δευτερον εχουμε πει πως ο δεικτης head εδω (list) στους κωδικες του migf1 δεν ειναι ο ιδιος κομβος
αλλα ειναι ενας δεικτης που δειχνει σε εναν κομβο... ωραια τοτε αυτο εδω γιατι
head->next=one;
εχει πεδιο next???