diff --git a/spring-2025/sen-107/00010/vipTaxi.c b/spring-2025/sen-107/00010/vipTaxi.c new file mode 100644 index 0000000..9c8bdd4 --- /dev/null +++ b/spring-2025/sen-107/00010/vipTaxi.c @@ -0,0 +1,115 @@ +/* VIP Taxi Queue + * Template for Fundamental Data Structures, skill 00010. + * + * Created by Pasin Manurangsi, 2025-01-08 + */ + #include + #include + #include + +// Variable declaration +#define MAX_NAME_LEN 25 +#define MAX_QUEUE_SIZE 30 + +// Structs +typedef struct Party +{ + char name[MAX_NAME_LEN]; + int rank; + int partyCount; + struct Party* next; +} Party; + +typedef struct Queue +{ + Party* front; + Party* rear; +} Queue; + +// Queue variable +Queue queue = { NULL, NULL }; + +// Qeue-related functions +void enqueue(int rank, const char* name, int partyCount) +{ + Party* newParty = (Party*)malloc(sizeof(Party)); + if (!newParty) + { + printf("Memory allocation failed!"); + return; + } + + strncpy(newParty->name, name, MAX_NAME_LEN - 1); + newParty->name[MAX_NAME_LEN - 1] = '\0'; + newParty->partyCount = partyCount; + newParty->next = NULL; + newParty->rank = rank; + + print("Create node"); + + if (queue.front == NULL) + { + printf("No queue, insert front"); + queue.front = newParty; + queue.rear = newParty; + } + else (newParty->rank > queue.front->rank); + { + printf("High rank, insert front"); + newParty->next + } +} + + /* Handle an arrival of a taxi. + */ +void taxiArrival() +{ + // ************** Please change the code below to your code ************** + printf("Please add your code to handle taxi arrival.\n"); +} + + /* Handles an arrival of a new party. + * Arguments: + * rank - the status of the party assumed to be one of 1, 2, 3, 4, 5 + * count - the number of people in the party + * name - the name of the party + */ +void partyArrival(int rank, int count, char name[]) +{ + // ************** Please change the code below to your code ************** + printf("Please add your code to handle party arrival.\n"); +} + +/* Free the contents of the datastructures used */ +void freeAll() +{ + // ************** Please change the code below to your code ************** + printf("Please add your code to free all datastructures.\n"); +} + +/* Main function loops for however many timesteps is specified, + * reading from the standard input and handling taxi / party arrivals + */ +int main(int argc, char* argv[]) +{ + int timesteps; // The total number of timesteps + char input[10]; // For the input prefix "Taxi" or "Party" + char name[25]; // The party name + int rank; // The party's status + int count; // The number of people in the party + scanf("%d", ×teps); + for (int i = 0 ; i < timesteps ; i ++) + { + scanf("\n%s", input); + if (strcmp(input, "Taxi") == 0) + { + taxiArrival(); + } + else + { + scanf(" %d %d %s", &rank, &count, name); + partyArrival(rank, count, name); + } + } + freeAll(); +} diff --git a/spring-2025/sen-107/00010/vipTaxi.in b/spring-2025/sen-107/00010/vipTaxi.in new file mode 100644 index 0000000..e9a564f --- /dev/null +++ b/spring-2025/sen-107/00010/vipTaxi.in @@ -0,0 +1,8 @@ +7 +Taxi +Party 3 2 Elon +Party 3 1 Bill +Party 5 3 Donald +Party 4 2 JD +Taxi +Taxi diff --git a/spring-2025/sen-107/00010/vipTaxi.out b/spring-2025/sen-107/00010/vipTaxi.out new file mode 100644 index 0000000..09255c5 --- /dev/null +++ b/spring-2025/sen-107/00010/vipTaxi.out @@ -0,0 +1,7 @@ +Empty Queue +Accepted +Accepted +Accepted +Rejected +Pick up party Donald with 3 people +Pick up party Elon with 2 people