I load a .csv file that fill my struct
typedef struct list TList;
struct list {
int index;
char data;
TList* prox;
};
How can I do a bubble sort in my list ?
I tried the follow
void bubble(TList *list, int siz) {
int c = 0;
int x, y, temp;
for (x = (siz - 1); x >= 0; x--) {
c++;
for (y = 1; y <= x; y++) {
c++;
if (list->index[y - 1] > list->index[y]) {
temp = list->index[y - 1];
list->index[y - 1] = list->index[y];
list->index[y] = temp;
}
}
}
printf("\nNeeded Steps: %i\n", c);
}
I think this is because the list->index[y]. It’s like a table in a database… at position 0 (index), I have the data, and the pointer to the next node. With list->index[..] I want to pass the position and get that node, like an array. It is a linked-list and prox needs to point to the next node. I filled my list with the data that came from a .csv file, and the list->prox points to the next node.
STL provides nice built-in sort algorithm. check http://www.cplusplus.com/reference/algorithm/