END_TEST START_TEST(test_list_rank) { int test_array[ARRAY_LEN]; list_t *list = list_new(); for (int i = 0 ; i < ARRAY_LEN ; i ++) { test_array[i] = i; list_append(list, &test_array[i]); } for (int i = 0 ; i < ARRAY_LEN ; i ++) { list_entry_t *e = list_rank(list, i); int *data = list_entry_data(e); fail_unless( *data == i, "The result data accessible through list_rank is erroneous" " rank no %d, *data == %d (should be %d)", i, *data, i); } list_delete(list); }
int main() { node *p, *q, *head; int n, i; head = p = q = NULL; scanf("%d", &n); for(i=1; i<=n; i++) { p=(node*)malloc(sizeof(node)); scanf("%u %s %s %d", &p->ID, &p->name, &p->gender, &p->score); if(head == NULL) head = p, q = p; else q->next = p, q = p; } if(q!=NULL) q->next = NULL; //end of creating student list head=list_sort(head); head=list_rank(head); //end of ranking scanf("%d", &n); for(i=1; i<=n; i++) { char cmd_string[4]; int cmd_rank; scanf("%s %d", cmd_string, &cmd_rank); if(!strcmp(cmd_string,"del")) head=delete_rank_from_list(head, cmd_rank); } printlist(head); return 0; }