made it compile

This commit is contained in:
Om Raheja 2024-08-28 18:28:53 -04:00
parent a1255b5c1a
commit 9281747d54
3 changed files with 22 additions and 21 deletions

10
rank.h
View File

@ -20,9 +20,9 @@ struct RankList
struct WRankList struct WRankList
{ {
int rank_count; int rank_count;
struct Weighted rank[M_STR]; struct Rank rank[M_STR];
struct Weighted srank[3][M_STR]; struct Rank srank[3][M_STR];
} };
struct Weighted struct Weighted
{ {
@ -43,7 +43,9 @@ struct WAlloc
}; };
void isort(char [][M_STR], struct Rank[], int); void isort(char [][M_STR], struct Rank[], int);
void rank(struct RankList *); void rank(struct Rank *, int);
void print_ranklist(struct RankList *); void print_ranklist(struct RankList *);
int rrlstdin(struct Rank[]);
#endif #endif

Binary file not shown.

View File

@ -59,8 +59,7 @@ main(int argc, char *argv[])
} }
items->rank_count = rrlstdin(items->rank); items->rank_count = rrlstdin(items->rank);
memcpy(items->srank, items->rank, sizeof(items->rank)); rank(items->srank, items->rank_count);
rank(items);
if (!weighted) { if (!weighted) {
// print the rank list // print the rank list
@ -114,11 +113,11 @@ main(int argc, char *argv[])
} }
printf(BOLDRED "\nRank according to %s\n\n" RESET, weighted.opt1); printf(BOLDRED "\nRank according to %s\n\n" RESET, weighted.opt1);
rank(&mem->r[0]); rank(mem->rl.srank[0], mem->rl.rank_count);
printf(BOLDRED "\nRank according to %s\n\n" RESET, weighted.opt2); printf(BOLDRED "\nRank according to %s\n\n" RESET, weighted.opt2);
rank(&mem->r[1]); rank(mem->rl.srank[1], mem->rl.rank_count);
printf(BOLDRED "\nRank according to %s\n\n" RESET, weighted.opt3); printf(BOLDRED "\nRank according to %s\n\n" RESET, weighted.opt3);
rank(&mem->r[2]); rank(mem->rl.srank[2], mem->rl.rank_count);
w_end: w_end:
@ -154,12 +153,13 @@ isort(char matrix[][M_STR], struct Rank to_sort[], int len) {
} }
int int
rrlstdin(struct Rank items[]) { rrlstdin(struct Rank items[])
{
printf(BOLDWHITE "Enter items...\n" RESET); printf(BOLDWHITE "Enter items...\n" RESET);
int i; int i;
for (i = 0; i < M_STR; i++) { for (i = 0; i < M_STR; i++) {
// local buffer for name // local buffer for name
char *name = items->rank[i].name; char *name = items[i].name;
puts(BOLDGREEN "> " RESET); puts(BOLDGREEN "> " RESET);
fgets(name, M_STR_LEN, stdin); fgets(name, M_STR_LEN, stdin);
@ -179,10 +179,13 @@ rrlstdin(struct Rank items[]) {
} }
name[nl] = '\0'; name[nl] = '\0';
} }
return i;
} }
void void
rank(struct RankList *items) { rank(struct Rank *items, int i)
{
// construct matrix of comparisons // construct matrix of comparisons
// NOTE: it doesn't actually store the "reason", // NOTE: it doesn't actually store the "reason",
// it just forces the user to type something out lol // it just forces the user to type something out lol
@ -194,19 +197,19 @@ rank(struct RankList *items) {
// compare all of the elements // compare all of the elements
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
for (int k = j + 1; k < i; k++) { for (int k = j + 1; k < i; k++) {
printf("%s vs %s (>/<): ", items->rank[j].name, items->rank[k].name); printf("%s vs %s (>/<): ", items[j].name, items[k].name);
// read one char, set matrix accordingly // read one char, set matrix accordingly
char c = getchar(); char c = getchar();
if (c == '>') { if (c == '>') {
matrix[j][k]++; matrix[j][k]++;
items->rank[j].score++; items[j].score++;
} else if (c == '<') { } else if (c == '<') {
matrix[k][j]++; matrix[k][j]++;
items->rank[k].score++; items[k].score++;
} else { } else {
printf("Setting to " BOLDRED "<" RESET ": %c\n", c); printf("Setting to " BOLDRED "<" RESET ": %c\n", c);
matrix[k][j]++; matrix[k][j]++;
items->rank[k].score++; items[k].score++;
} }
// clear input buffer // clear input buffer
@ -220,12 +223,8 @@ rank(struct RankList *items) {
} }
} }
memcpy(items->srank, items->rank, sizeof(struct Rank) * M_STR);
items->rank_count = i;
// insertion sort: the array **should be** nearly sorted // insertion sort: the array **should be** nearly sorted
isort(matrix, items->srank, i); isort(matrix, items, i);
} }
void void