test_list.c #include "list.h" #include <stdio.h> #include <stdlib.h> int main (){ char ans[2]; int num; struct node *head = NULL; do { do { printf("Enter a number: "); scanf("%d", &num); head = push(head, num);//Can change to append printf("Do you want another num (y or n): "); scanf("%1s",ans); } while(ans[0] == 'y'); printf("Sort ascending or descending (a or d)? "); scanf("%1s",ans); if(ans[0] == 'a') head=sort_ascending(head); else if(ans[0] == 'd') head=sort_descending(head); print(head, length(head)); printf("Do you want to do this again (y or n)? "); scanf("%1s",ans); if(ans[0] == 'y') head = clear(head); } while(ans[0] == 'y'); return 0; }
void highscore_controller::add_score(int score) { for (int i = 0; i < MAX_AMOUNT_OF_HIGHSCORE; i++) { if (score > highscores[i]) { for (int j = i + 1; j > MAX_AMOUNT_OF_HIGHSCORE; j++) { if (j + 1 < MAX_AMOUNT_OF_HIGHSCORE) { highscores[j + 1] = highscores[j]; } } highscores[i] = score; break; } } sort_descending(); }
void add_numerals(char* result,size_t result_length, const char * first_numeral, const char * second_numeral) { if(!validate_buffer(result_length)) return; result[0] = '\0'; char first_numeral_substituted[MAX_NUMERAL_SIZE]; char second_numeral_substituted[MAX_NUMERAL_SIZE]; strcpy(first_numeral_substituted, first_numeral); strcpy(second_numeral_substituted, second_numeral); substitute_out_subtractives(first_numeral_substituted); substitute_out_subtractives(second_numeral_substituted); strcpy(result, first_numeral_substituted); strcat(result, second_numeral_substituted); sort_descending(result); combine_groups(result); substitute_in_subtractives(result); }
int main(void) { int i, n, head, last; n = 500; for (i = 0; i < n; i++) nodes[i].val = rand() % (n * n); head = sort_descending(nodes, n); // Make sure we're sorted descending and print. last = -1; for (i = head; i != -1; i = nodes[i].next) { printf("%d ", nodes[i].val); if (last != -1 && nodes[i].val > last) { printf("oops!\n"); return 1; } last = nodes[i].val; } printf("\n"); return 0; }
int main (){ char ans[2]; int num; struct node *head = NULL; struct node * tail = NULL; do { do { printf("Enter a number: "); scanf("%d", &num); // printf("hi"); head = push(head, num);//Can change to append //printf("%d", length(head)); printf("Do you want another num (y or n): "); scanf("%1s",ans); } while(ans[0] == 'y'); //head = insert_middle(head, 1, 4); //printf("4 was inserted into index 1 \n"); //head = remove_node(head, 3); //printf("all 3's were removed from the list \n"); printf("Sort ascending or descending (a or d)? "); scanf("%1s",ans); if(ans[0] == 'a') head=sort_ascending(head); else if(ans[0] == 'd') head=sort_descending(head); //head = insert_middle(head, 3, 1); print(head, length(head)); printf("Do you want to do this again (y or n)? "); scanf("%1s",ans); if(ans[0] == 'y') head = clear(head); //print(head, length(head)); // printf("%d", length(head)); } while(ans[0] == 'y'); return 0; }
highscore_controller::highscore_controller(int *predefined_scores) { for (int i = 0; i < MAX_AMOUNT_OF_HIGHSCORE; i++) { highscores[i] = predefined_scores[i]; } sort_descending(); }