Classificação de bolha na lista vinculada c [fechada]
Eu preciso fazer é ler em um arquivo de entrada em uma lista vinculada. Parte do arquivo é:
NomeA, 25
NomeB, 33
NomeC, 23
NomeD, 39
E depois eu preciso classificar pelo número (classificação de bolha) e gravá-lo em outro arquivo.
Aqui está o que eu tenho:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node{
char name[20];
int number;
struct node *next;
struct node *prev;
}*head;
int main(void) {
struct node *temp;
temp = malloc(sizeof(struct node));
temp->next = NULL;
head = temp;
FILE *ifp;
char fnamer[100] = "";
char line[128];
// printf("\n\nPlease Enter the Full Path of the file: \n");
// scanf("%s",&fnamer);
ifp = fopen("mintaadatok.txt", "r");
if (ifp == NULL) {
printf("\n%s\" File NOT FOUND!", fnamer);
exit(1);
}
int c = 0;
char buffer[1024];
memset(buffer, 0, 1024);
while (c < 15) {
fgets(buffer, 1024, ifp);
sscanf(buffer, "%19[^,], %d", temp->name, &temp->number);
printf("%d %s %d\n", c, temp->name, temp->number);
temp->next = malloc(sizeof(struct node));
temp = temp->next;
temp->next = NULL;
c++;
}
int i,step;
for (temp = head; temp; temp = temp->next) {
printf("%s", temp->name);
printf("%d\n", temp->number);
for(step=0;step<10-1;++step)
for(i=0;i<10-step-1;++i)
{
temp->next = malloc(sizeof(struct node));
if(temp->number>temp->next)
{
temp=temp->number;
temp->number=temp->next;
temp->next=temp;
}
}
}
printf("In ascending order: ");
}
Você pode me ajudar a classificar esses dados?