Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PRÁCTICA DE QUICKSORT
#include <stdio.h> #include <stdlib.h> typedef struct { char name[101]; unsigned short age; float score; }player; // --------------------Prototypes-------------------- void input( player *, unsigned short ); int compareScore( const void * , const void * ); // ---------------------------Main Program------------------------ int main(void) { player listOfPlayers[10000]; unsigned short total, i; scanf("%hu\n", &total); input(listOfPlayers, total); qsort(listOfPlayers, total, sizeof(player), compareScore); printf("\nORDER BY SCORE\n"); printf("==============\n"); for ( i = 0 ; i < total ; i ++ ) printf("%s %hu %.1f\n", listOfPlayers[i].name, listOfPlayers[i].age, listOfPlayers[i].score); return 0; } //------------------------------Functions---------------------------------- void input( player *list, unsigned short total) { unsigned short i; for ( i = 0 ; i < total ; i ++ ) { scanf("%100[^,]s", list[i].name); getchar(); scanf("%hu", &list[i].age); getchar(); scanf("%f", &list[i].score); getchar(); } for ( i = 0 ; i < total ; i ++ ) printf("%s %hu %.1f\n", list[i].name, list[i].age, list[i].score); } int compareScore( const void *pivot , const void *element ) { player *ptrPivot = ( player * ) pivot; player *ptrElement = ( player * ) element; return (ptrElement -> score) - (ptrPivot -> score); }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Michael Bean's Spring 2017 Lab 3 v1.1
Lab6 v1.3Sin,cos,tan,cot
multiplication
SOLUCION USANDO UN CICLO Y PUNTERO
test
Program to input form command line and print it
18BCE2182 ASSESS_2 Q1
ALPAHABET PATTERNS
Star 1,3
Linear Searching
Please log in to post a comment.