hi
also ich hab mich mal an listen probiert. funktioniert auch alles wunderbar.
jetzt hab ich mir mal eine funktion gebastelt die zwei listen vergleichen soll, wenn ein element in beiden listen vorkommt wird es aus der einen liste gelöscht, aber irgentwie scheint es nicht zu funkionieren. ich bekomme immer
eine speicherzugriffsverletzung wenn die innere while schleife das zweite mal
durchlaufen wird.
inhalt von pTmpLeft ;
Hello
World
This
Is
The
First
Test
inhalt von pTmpLeft ;
Hello
Folks
This
Is
The
Second
Test
PHP-Code:
// standart type of a element
typedef const char *ListKeyType;
// define elment
typedef struct Node {
ListKeyType cRule;
struct Node *Next;
}*ListNode;
//define list
typedef ListNode List;
.
.
.
//compare list
//is a part in pRootLeft and pRootRight then remove this part from pRootLeft
int comparelist( List *pRootLeft, List *pRootRight ) {
List pTmpLeft, pTmpRight; //temp lists
int EOLLeft, EOLRight; //fake bool value, end of list
if ( NULL == *pRootLeft ) { //extreme paranoia
perror("comparelist( pRootLeft, ), no list create? ");
return(-1);
}
if ( NULL == *pRootRight ) { //extreme paranoia
perror("comparelist( , pRootRight ), no list create? ");
return(-1);
}
pTmpLeft = *pRootLeft;
pTmpRight = *pRootRight;
EOLLeft = 0;
EOLRight = 0;
//compare one left element with all right elements
//and go to next left element and than the same stuff
while( !EOLLeft ) {
if ( NULL == pTmpLeft->Next ) { //next element is not empty
EOLLeft = 1;
}
printf("LEFT : %s\n", pTmpLeft->cRule);
while( !EOLRight ) {
if ( NULL == pTmpRight->Next ) { //next element is not empty
EOLRight = 1;
}
printf("Right : %s\n", pTmpRight->cRule);
if ( 0 == strcmp( pTmpLeft->cRule, pTmpRight->cRule ) ) {
pTmpLeft = pTmpLeft->Next;
}
pTmpRight = pTmpRight->Next;
}
pTmpLeft = pTmpLeft->Next;
EOLRight = 0;
}
return(0);
}
habe vorsichtshalber den ganzen quellcode noch drangehangen ...
Pinocchino
P.S. tut mir ein gefallen und meckert nicht über meine rechtschreibung/gramatik ich musste mich beeilen dies zu schreiben.
Lesezeichen