Mein Funktionseinsatz funktioniert nicht, nachdem ich einige Sortiermethoden angewendet habe, die ich bei Google bekommen habe (http://teknosrc.com/linked-list-in-c-insertion-sort/).C - Segmentierungsfehler - Einfügung_Sortierungsfunktion der verketteten Liste
Erstens sind die Strukturen, die ich an, es benutzen werde:
// This is the Node , where will be stored the item
struct no
{
Item * item;
struct no *prox;
};
typedef struct no No;
//This is the list, where will have the head node(No)
struct lista
{
char *nomeLista; //This is just a name of the list
No *cabeca; //This is the head node
int tamanho; //This is the amount of items inserted (forgot to implement this)
struct lista *prox; //This is the next list
};
typedef struct lista Lista;
//This is just the main list that will guard all the list of nodes in a linked way. No need to worry about this.
struct vetorListas
{
Lista *cabeca; //head list
int tamanho; //amount of lists
};
typedef struct vetorListas VetorListas;
//This is the item to be inserted
struct item
{
int id; //the ID used for the comparison of sort
char *nome; //just the name of it
};
typedef struct item Item;
In dieser Funktion nomeDaList
ist ein String (char *) verwendet, um die Liste zu finden, indem andere Funktion und i
ist die Item
:
void *
insert(void * nomeDaLista, Item * i)
{
Lista * auxLista; //the list
auxLista = idl(nomeDaLista); //the function to get the list by it's name. It works, no worries.
//down here, is the sequence of codes translated to my program (got by the website I showed before)
No * temp = auxLista->cabeca;
No * prev = NULL;
No * ptr;
Item * itemTemp;
itemTemp = temp->item;
ptr = criaNo(i); //this function creates (makes the malloc and all) a node (No) and return the created node.
if(temp == NULL)
{
ptr->prox=NULL;
auxLista->cabeca = ptr;
return auxLista;
}
if(i->id < itemTemp->id)
{
ptr->prox = auxLista->cabeca;
auxLista->cabeca = ptr;
return auxLista;
} else
{
while(temp != NULL)
{
if(i->id > itemTemp->id)
{
prev = temp;
temp = temp->prox;
continue;
} else
{
prev->prox = ptr;
ptr->prox = temp;
return auxLista;
}
}
prev->prox = ptr;
}
}
Bitte helfen Sie mit dieser Segmentierung Fehler (Core Dumped).
'if (temp == NULL)': Sie haben 'temp' bereits bei' itemTemp = temp-> item; 'verwendet. – BLUEPIXY
..die Sie hätten sehen können, wenn Sie Ihren Debugger verwendet hätten :( –
Also, sollte ich Kommentar if (temp == NULL)? Könnte immer noch nicht verstehen, was zu tun ist ... und es tut mir leid, ich habe keine IDE und Ich kann nicht mit gdd umgehen. –