Heres my program... that doesnt work completely
Code:
#include <stdio.h> /* for printf */
#include <stdlib.h> /* for malloc */
typedef struct node{
char player_id[7];
int level;
int score;
struct node *next; /* pointer to next element in list */
} *LIST;
LIST new_list() // Create new list by creating sentinel node
{
LIST list = (LIST) malloc(sizeof(struct node));
list->next = NULL;
return list;
}
// Add node to beginning of list
LIST list_add(LIST list, int i)
{
LIST new_node = (LIST) malloc(sizeof(struct node));
if (new_node == NULL)
return NULL;
new_node->score = i;
new_node->next = list;
return new_node;
}
LIST list_remove(LIST list) /* remove node */
{
LIST n;
if (list->next == NULL)
{
return list;
}
if (list != NULL)
{
n = list->next;
free(list);
return n;
}
else
return NULL;
}
LIST *sortlist(LIST list)
{
LIST sorted;
if (list !=NULL)
}
void list_print(LIST list)
{
if (list == NULL)
{
printf("list is empty\n");
}
while (list != NULL)
{
printf("score: %d\n", list->score);
list = list->next;
}
}
int main(void)
{
LIST slist;
while(gets(line) != NULL){
int i;
LIST *array;
array = (LIST *)malloc(16*sizeof(LIST)); //need 16 because I have 15 levels
//then what do I do??
slist = new_list();
for (i = 0; i < len; i++)
{
printf("Enter a score: ");
scanf("%d", &array[i]);
//printf("%d\n", array[i]);
slist = list_add(slist, array[i]);
}
list_print(slist);
return 0;
}
I tried to write something for the sort list function... but I dont understand what to do?.. please.. some code would really be helpful.. then I have to try and implement it..
I have an array of levels .. each of which have a different linked list with 3 types of data in each element. I need the linked list to sort with respect to the score that is inputed..greatest to least.. but it only can be compared to that level. So in other words.. I have an array of linked lists that need sorting... but as of right now I cant even get my data to go into the array..
input ::
name level score
joe 5 400
matt 6 300
eric 5 450
Can anyone help me with any of my problems listed above?? PLEASE