Compare commits
14 Commits
90bdecd365
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b0d1b5ed7 | |||
| caee955384 | |||
| ee7a5389c9 | |||
| d43edbf475 | |||
| 094998cc79 | |||
| 139b370552 | |||
| cbd1003ebb | |||
| 80a8b001de | |||
| a290788bd3 | |||
| e13be3a0b6 | |||
| cd08400d5f | |||
| c005c34103 | |||
| c8f250e9d6 | |||
| 579fa56ae8 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1 +1,4 @@
|
||||
*.bin
|
||||
*.bin
|
||||
|
||||
.idea
|
||||
*.out
|
||||
@@ -1,3 +1,5 @@
|
||||
### Guide
|
||||
#### Compile
|
||||
```shell
|
||||
gcc q1.c -o q1
|
||||
./q1
|
||||
@@ -485,7 +485,10 @@ again:
|
||||
printf("\nRecord saved successfully!\n");
|
||||
|
||||
// reload data into linked list again
|
||||
read_file();
|
||||
// read_file();
|
||||
|
||||
// show back the all results
|
||||
display_students();
|
||||
}
|
||||
|
||||
void read_file()
|
||||
79
final/q2.c
Normal file
79
final/q2.c
Normal file
@@ -0,0 +1,79 @@
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
|
||||
#define STUDENT_ID_SIZE 10
|
||||
#define CHAR_INT '0'
|
||||
|
||||
struct studentID
|
||||
{
|
||||
int value;
|
||||
struct studentID *next;
|
||||
};
|
||||
|
||||
typedef struct studentID STUDENTID;
|
||||
typedef STUDENTID *STUDENTIDPtr;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
const char student_id[] = "1001245345";
|
||||
|
||||
// 1. creation nodes
|
||||
size_t student_id_len = sizeof(student_id) / sizeof(student_id[0]) - 1;
|
||||
|
||||
STUDENTIDPtr student_ptr_1 = (STUDENTIDPtr)malloc(sizeof(STUDENTID));
|
||||
STUDENTIDPtr student_ptr_2 = (STUDENTIDPtr)malloc(sizeof(STUDENTID));
|
||||
STUDENTIDPtr student_ptr_3 = (STUDENTIDPtr)malloc(sizeof(STUDENTID));
|
||||
STUDENTIDPtr student_ptr_4 = (STUDENTIDPtr)malloc(sizeof(STUDENTID));
|
||||
STUDENTIDPtr student_ptr_5 = (STUDENTIDPtr)malloc(sizeof(STUDENTID));
|
||||
|
||||
student_ptr_1->next = student_ptr_2;
|
||||
student_ptr_2->next = student_ptr_3;
|
||||
student_ptr_3->next = student_ptr_4;
|
||||
student_ptr_4->next = student_ptr_5;
|
||||
student_ptr_5->next = NULL;
|
||||
|
||||
// 2. fill the node's values
|
||||
STUDENTIDPtr temp = student_ptr_1;
|
||||
int last_len = 5;
|
||||
while (temp != NULL)
|
||||
{
|
||||
temp->value = student_id[student_id_len - last_len] - CHAR_INT;
|
||||
temp = temp->next;
|
||||
last_len--;
|
||||
}
|
||||
|
||||
// 3. removes dup
|
||||
STUDENTIDPtr temp1, temp2, duplicate;
|
||||
temp1 = student_ptr_1;
|
||||
|
||||
while (temp1 != NULL && temp1->next != NULL)
|
||||
{
|
||||
temp2 = temp1;
|
||||
|
||||
while (temp2->next != NULL)
|
||||
{
|
||||
if (temp1->value == temp2->next->value)
|
||||
{
|
||||
duplicate = temp2->next;
|
||||
temp2->next = temp2->next->next;
|
||||
free(duplicate);
|
||||
}
|
||||
else
|
||||
temp2 = temp2->next;
|
||||
}
|
||||
temp1 = temp1->next;
|
||||
}
|
||||
|
||||
// output the result
|
||||
while (student_ptr_1 != NULL)
|
||||
{
|
||||
printf("%d ", student_ptr_1->value);
|
||||
student_ptr_1 = student_ptr_1->next;
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
286
final/q3.c
Normal file
286
final/q3.c
Normal file
@@ -0,0 +1,286 @@
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "time.h"
|
||||
|
||||
#define DEPOT_SIZE 10
|
||||
|
||||
struct Bus
|
||||
{
|
||||
int BusID;
|
||||
int RouteID;
|
||||
time_t schedule;
|
||||
} Depot[DEPOT_SIZE];
|
||||
|
||||
typedef enum
|
||||
{
|
||||
true,
|
||||
false
|
||||
} bool;
|
||||
|
||||
void createBuses();
|
||||
void printBuses();
|
||||
void scheduleBuses();
|
||||
void alignupBuses();
|
||||
void releaseBuses();
|
||||
void emergency();
|
||||
|
||||
// utils variable
|
||||
bool has_created = false;
|
||||
bool has_scheduled = false;
|
||||
bool has_aligned = false;
|
||||
int top = -1;
|
||||
|
||||
// utils function
|
||||
void clrscr();
|
||||
void print_depot(struct Bus *depot);
|
||||
|
||||
time_t get_random_time();
|
||||
|
||||
void confirm_on_finish();
|
||||
int quicksort_compare_func(const void *elem1, const void *elem2);
|
||||
bool isEmpty();
|
||||
int menu();
|
||||
|
||||
void remove_index_of_array(int index);
|
||||
|
||||
// Main Function
|
||||
int main()
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
int selection = menu();
|
||||
clrscr();
|
||||
printf("You Select : %d", selection);
|
||||
printf("\n");
|
||||
|
||||
switch (selection)
|
||||
{
|
||||
case 1:
|
||||
createBuses();
|
||||
break;
|
||||
case 2:
|
||||
printBuses();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
scheduleBuses();
|
||||
break;
|
||||
case 4:
|
||||
alignupBuses();
|
||||
break;
|
||||
|
||||
case 5:
|
||||
releaseBuses();
|
||||
break;
|
||||
|
||||
case 6:
|
||||
emergency();
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("You are enter incorrect option number");
|
||||
}
|
||||
|
||||
confirm_on_finish();
|
||||
};
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int menu()
|
||||
{
|
||||
fflush(stdout);
|
||||
|
||||
clrscr();
|
||||
|
||||
printf("\nQuestion 3 ");
|
||||
printf("\n=========================================");
|
||||
printf("\n");
|
||||
printf("\n1. Create Buses");
|
||||
printf("\n2. Print Buses");
|
||||
printf("\n3. Schedule Buses");
|
||||
printf("\n4. Align up Buses");
|
||||
printf("\n5. Release Buses");
|
||||
printf("\n6. Emergency Buses");
|
||||
|
||||
int chosen;
|
||||
printf("\n\nEnter Your Selection : ");
|
||||
scanf("%d", &chosen);
|
||||
return chosen;
|
||||
}
|
||||
|
||||
void createBuses()
|
||||
{
|
||||
|
||||
if (has_created == true)
|
||||
{
|
||||
printf("\nYou have created already...");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\n\nStart Create Buses...");
|
||||
|
||||
for (int i = 0; i < DEPOT_SIZE; i++)
|
||||
{
|
||||
top++;
|
||||
Depot[i].BusID = i + 1;
|
||||
Depot[i].RouteID = 1000 + (i + i);
|
||||
printf("\n - Starting Create Bus %d", i + 1);
|
||||
}
|
||||
|
||||
has_created = true;
|
||||
|
||||
printf("\nFinish Created Buses");
|
||||
}
|
||||
|
||||
void printBuses()
|
||||
{
|
||||
if (has_created == false)
|
||||
{
|
||||
printf("\nPlease Create Buses First!");
|
||||
return;
|
||||
}
|
||||
print_depot(Depot);
|
||||
}
|
||||
|
||||
void scheduleBuses()
|
||||
{
|
||||
if (has_created == false)
|
||||
{
|
||||
printf("\nPlease Create Buses First!");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\nStart Scheduling Buses...\n\n");
|
||||
|
||||
size_t currentLen = sizeof(Depot) / sizeof(Depot[0]);
|
||||
|
||||
for (int i = 0; i < currentLen; i++)
|
||||
{
|
||||
printf("\n - Start Random Schedule %d...", i);
|
||||
|
||||
Depot[i].schedule = get_random_time();
|
||||
}
|
||||
|
||||
printf("\n\nEnd Scheduling Buses...");
|
||||
|
||||
has_scheduled = true;
|
||||
}
|
||||
|
||||
void print_depot(struct Bus *depot)
|
||||
{
|
||||
|
||||
size_t currentLen = sizeof(Depot) / sizeof(*Depot);
|
||||
|
||||
for (int i = 0; i < top; i++)
|
||||
{
|
||||
printf("Bus ID: %d\n", depot[i].BusID);
|
||||
printf("Route ID: %d\n", depot[i].RouteID);
|
||||
|
||||
char *scheduleForShow = "";
|
||||
if (depot[i].schedule != 0)
|
||||
{
|
||||
scheduleForShow = ctime(&depot[i].schedule);
|
||||
}
|
||||
|
||||
printf("Schdule Time : %s\n\n", scheduleForShow);
|
||||
}
|
||||
}
|
||||
|
||||
void alignupBuses()
|
||||
{
|
||||
if (has_scheduled == false)
|
||||
{
|
||||
printf("\n\nYou are not scheduling buses yet ...");
|
||||
return;
|
||||
}
|
||||
size_t currentLen = sizeof(Depot) / sizeof(Depot[0]);
|
||||
|
||||
qsort(Depot, sizeof(Depot) / sizeof(*Depot), sizeof(*Depot), quicksort_compare_func);
|
||||
|
||||
printf("\n\nFinish Align up Buses Schedule ... ");
|
||||
has_aligned = true;
|
||||
}
|
||||
|
||||
void releaseBuses()
|
||||
{
|
||||
if (has_aligned == false)
|
||||
{
|
||||
printf("\n\nYou are not align buses schedule yet ...");
|
||||
return;
|
||||
}
|
||||
|
||||
int last_index = sizeof(Depot) / sizeof(*Depot) - 1;
|
||||
|
||||
remove_index_of_array(last_index);
|
||||
|
||||
printf("\n\nRelease Complete...\n\n");
|
||||
}
|
||||
|
||||
void emergency()
|
||||
{
|
||||
if (has_aligned == false)
|
||||
{
|
||||
printf("\n\nYou are not align buses schedule yet ...");
|
||||
return;
|
||||
}
|
||||
|
||||
remove_index_of_array(0);
|
||||
|
||||
printf("\n\nRelease Complete...\n\n");
|
||||
}
|
||||
|
||||
void remove_index_of_array(int remove_index)
|
||||
{
|
||||
|
||||
int current_len = sizeof(Depot) / sizeof(*Depot);
|
||||
memmove(Depot + remove_index, Depot + remove_index + 1, (sizeof(Depot) - remove_index - 1) * sizeof(*Depot));
|
||||
top--;
|
||||
}
|
||||
|
||||
time_t get_random_time()
|
||||
{
|
||||
time_t currentTime;
|
||||
|
||||
time(¤tTime);
|
||||
|
||||
long currentTimeNumber = (long)localtime(¤tTime);
|
||||
|
||||
// Random in next 5 hours
|
||||
long randomAddOnTime = rand() % (60 * 60 * 5);
|
||||
|
||||
long additionTime = currentTimeNumber + randomAddOnTime;
|
||||
|
||||
return additionTime;
|
||||
}
|
||||
|
||||
void clrscr()
|
||||
{
|
||||
system("clear");
|
||||
}
|
||||
|
||||
void confirm_on_finish()
|
||||
{
|
||||
|
||||
printf("\n\nPress Enter to Back to Menu...");
|
||||
|
||||
getchar();
|
||||
getchar();
|
||||
}
|
||||
|
||||
bool isFull()
|
||||
{
|
||||
return top == -1;
|
||||
}
|
||||
|
||||
int quicksort_compare_func(const void *elem1, const void *elem2)
|
||||
{
|
||||
struct Bus element1 = *((struct Bus *)elem1);
|
||||
struct Bus element2 = *((struct Bus *)elem2);
|
||||
if (element1.schedule > element2.schedule)
|
||||
return -1;
|
||||
if (element1.schedule < element2.schedule)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
2
run
2
run
@@ -7,4 +7,4 @@
|
||||
|
||||
rm -r single.bin
|
||||
|
||||
gcc work1/single.c -o single.bin && ./single.bin
|
||||
gcc work1/q3.c -o single.bin && ./single.bin
|
||||
BIN
swi-final.zip
Normal file
BIN
swi-final.zip
Normal file
Binary file not shown.
@@ -485,7 +485,9 @@ again:
|
||||
printf("\nRecord saved successfully!\n");
|
||||
|
||||
// reload data into linked list again
|
||||
read_file();
|
||||
// read_file();
|
||||
|
||||
display_students();
|
||||
}
|
||||
|
||||
void read_file()
|
||||
83
work1/q2.c
Normal file
83
work1/q2.c
Normal file
@@ -0,0 +1,83 @@
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
|
||||
#define STUDENT_ID_SIZE 10
|
||||
#define CHAR_INT '0'
|
||||
|
||||
struct studentID
|
||||
{
|
||||
int value;
|
||||
struct studentID *next;
|
||||
};
|
||||
|
||||
typedef struct studentID STUDENTID;
|
||||
typedef STUDENTID *STUDENTIDPtr;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
const char student_id[] = "1001245345";
|
||||
|
||||
// printf("Student ID: %s\n", student_id);
|
||||
|
||||
// memcpy(five_digits, &student_id[5], 5);
|
||||
// five_digits[5] = '\0';
|
||||
|
||||
// creation nodes
|
||||
size_t student_id_len = sizeof(student_id) / sizeof(student_id[0]) - 1;
|
||||
|
||||
STUDENTIDPtr student_ptr_1 = (STUDENTIDPtr)malloc(sizeof(STUDENTID));
|
||||
STUDENTIDPtr student_ptr_2 = (STUDENTIDPtr)malloc(sizeof(STUDENTID));
|
||||
STUDENTIDPtr student_ptr_3 = (STUDENTIDPtr)malloc(sizeof(STUDENTID));
|
||||
STUDENTIDPtr student_ptr_4 = (STUDENTIDPtr)malloc(sizeof(STUDENTID));
|
||||
STUDENTIDPtr student_ptr_5 = (STUDENTIDPtr)malloc(sizeof(STUDENTID));
|
||||
|
||||
student_ptr_1->next = student_ptr_2;
|
||||
student_ptr_2->next = student_ptr_3;
|
||||
student_ptr_3->next = student_ptr_4;
|
||||
student_ptr_4->next = student_ptr_5;
|
||||
student_ptr_5->next = NULL;
|
||||
|
||||
// fill the node's values
|
||||
STUDENTIDPtr temp = student_ptr_1;
|
||||
int last_len = 5;
|
||||
while (temp != NULL)
|
||||
{
|
||||
temp->value = student_id[student_id_len - last_len] - CHAR_INT;
|
||||
temp = temp->next;
|
||||
last_len--;
|
||||
}
|
||||
|
||||
// removes dup
|
||||
STUDENTIDPtr temp1, temp2, duplicate;
|
||||
temp1 = student_ptr_1;
|
||||
|
||||
while (temp1 != NULL && temp1->next != NULL)
|
||||
{
|
||||
temp2 = temp1;
|
||||
|
||||
while (temp2->next != NULL)
|
||||
{
|
||||
if (temp1->value == temp2->next->value)
|
||||
{
|
||||
duplicate = temp2->next;
|
||||
temp2->next = temp2->next->next;
|
||||
free(duplicate);
|
||||
}
|
||||
else
|
||||
temp2 = temp2->next;
|
||||
}
|
||||
temp1 = temp1->next;
|
||||
}
|
||||
|
||||
while (student_ptr_1 != NULL)
|
||||
{
|
||||
printf("%d ", student_ptr_1->value);
|
||||
student_ptr_1 = student_ptr_1->next;
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
286
work1/q3.c
Normal file
286
work1/q3.c
Normal file
@@ -0,0 +1,286 @@
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "time.h"
|
||||
|
||||
#define DEPOT_SIZE 10
|
||||
|
||||
struct Bus
|
||||
{
|
||||
int BusID;
|
||||
int RouteID;
|
||||
time_t schedule;
|
||||
} Depot[DEPOT_SIZE];
|
||||
|
||||
typedef enum
|
||||
{
|
||||
true,
|
||||
false
|
||||
} bool;
|
||||
|
||||
void createBuses();
|
||||
void printBuses();
|
||||
void scheduleBuses();
|
||||
void alignupBuses();
|
||||
void releaseBuses();
|
||||
void emergency();
|
||||
|
||||
// utils variable
|
||||
bool has_created = false;
|
||||
bool has_scheduled = false;
|
||||
bool has_aligned = false;
|
||||
int top = -1;
|
||||
|
||||
// utils function
|
||||
void clrscr();
|
||||
void print_depot(struct Bus *depot);
|
||||
|
||||
time_t get_random_time();
|
||||
|
||||
void confirm_on_finish();
|
||||
int quicksort_compare_func(const void *elem1, const void *elem2);
|
||||
bool isEmpty();
|
||||
int menu();
|
||||
|
||||
void remove_index_of_array(int index);
|
||||
|
||||
// Main Function
|
||||
int main()
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
int selection = menu();
|
||||
clrscr();
|
||||
printf("You Select : %d", selection);
|
||||
printf("\n");
|
||||
|
||||
switch (selection)
|
||||
{
|
||||
case 1:
|
||||
createBuses();
|
||||
break;
|
||||
case 2:
|
||||
printBuses();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
scheduleBuses();
|
||||
break;
|
||||
case 4:
|
||||
alignupBuses();
|
||||
break;
|
||||
|
||||
case 5:
|
||||
releaseBuses();
|
||||
break;
|
||||
|
||||
case 6:
|
||||
emergency();
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("You are enter incorrect option number");
|
||||
}
|
||||
|
||||
confirm_on_finish();
|
||||
};
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int menu()
|
||||
{
|
||||
fflush(stdout);
|
||||
|
||||
clrscr();
|
||||
|
||||
printf("\nQuestion 3 ");
|
||||
printf("\n=========================================");
|
||||
printf("\n");
|
||||
printf("\n1. Create Buses");
|
||||
printf("\n2. Print Buses");
|
||||
printf("\n3. Schedule Buses");
|
||||
printf("\n4. Align up Buses");
|
||||
printf("\n5. Release Buses");
|
||||
printf("\n6. Emergency Buses");
|
||||
|
||||
int chosen;
|
||||
printf("\n\nEnter Your Selection : ");
|
||||
scanf("%d", &chosen);
|
||||
return chosen;
|
||||
}
|
||||
|
||||
void createBuses()
|
||||
{
|
||||
|
||||
if (has_created == true)
|
||||
{
|
||||
printf("\nYou have created already...");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\n\nStart Create Buses...");
|
||||
|
||||
for (int i = 0; i < DEPOT_SIZE; i++)
|
||||
{
|
||||
top++;
|
||||
Depot[i].BusID = i + 1;
|
||||
Depot[i].RouteID = 1000 + (i + i);
|
||||
printf("\n - Starting Create Bus %d", i + 1);
|
||||
}
|
||||
|
||||
has_created = true;
|
||||
|
||||
printf("\nFinish Created Buses");
|
||||
}
|
||||
|
||||
void printBuses()
|
||||
{
|
||||
if (has_created == false)
|
||||
{
|
||||
printf("\nPlease Create Buses First!");
|
||||
return;
|
||||
}
|
||||
print_depot(Depot);
|
||||
}
|
||||
|
||||
void scheduleBuses()
|
||||
{
|
||||
if (has_created == false)
|
||||
{
|
||||
printf("\nPlease Create Buses First!");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\nStart Scheduling Buses...\n\n");
|
||||
|
||||
size_t currentLen = sizeof(Depot) / sizeof(Depot[0]);
|
||||
|
||||
for (int i = 0; i < currentLen; i++)
|
||||
{
|
||||
printf("\n - Start Random Schedule %d...", i);
|
||||
|
||||
Depot[i].schedule = get_random_time();
|
||||
}
|
||||
|
||||
printf("\n\nEnd Scheduling Buses...");
|
||||
|
||||
has_scheduled = true;
|
||||
}
|
||||
|
||||
void print_depot(struct Bus *depot)
|
||||
{
|
||||
|
||||
size_t currentLen = sizeof(Depot) / sizeof(*Depot);
|
||||
|
||||
for (int i = 0; i < top; i++)
|
||||
{
|
||||
printf("Bus ID: %d\n", depot[i].BusID);
|
||||
printf("Route ID: %d\n", depot[i].RouteID);
|
||||
|
||||
char *scheduleForShow = "";
|
||||
if (depot[i].schedule != 0)
|
||||
{
|
||||
scheduleForShow = ctime(&depot[i].schedule);
|
||||
}
|
||||
|
||||
printf("Schdule Time : %s\n\n", scheduleForShow);
|
||||
}
|
||||
}
|
||||
|
||||
void alignupBuses()
|
||||
{
|
||||
if (has_scheduled == false)
|
||||
{
|
||||
printf("\n\nYou are not scheduling buses yet ...");
|
||||
return;
|
||||
}
|
||||
size_t currentLen = sizeof(Depot) / sizeof(Depot[0]);
|
||||
|
||||
qsort(Depot, sizeof(Depot) / sizeof(*Depot), sizeof(*Depot), quicksort_compare_func);
|
||||
|
||||
printf("\n\nFinish Align up Buses Schedule ... ");
|
||||
has_aligned = true;
|
||||
}
|
||||
|
||||
void releaseBuses()
|
||||
{
|
||||
if (has_aligned == false)
|
||||
{
|
||||
printf("\n\nYou are not align buses schedule yet ...");
|
||||
return;
|
||||
}
|
||||
|
||||
int last_index = sizeof(Depot) / sizeof(*Depot) - 1;
|
||||
|
||||
remove_index_of_array(last_index);
|
||||
|
||||
printf("\n\nRelease Complete...\n\n");
|
||||
}
|
||||
|
||||
void emergency()
|
||||
{
|
||||
if (has_aligned == false)
|
||||
{
|
||||
printf("\n\nYou are not align buses schedule yet ...");
|
||||
return;
|
||||
}
|
||||
|
||||
remove_index_of_array(0);
|
||||
|
||||
printf("\n\nRelease Complete...\n\n");
|
||||
}
|
||||
|
||||
void remove_index_of_array(int remove_index)
|
||||
{
|
||||
|
||||
int current_len = sizeof(Depot) / sizeof(*Depot);
|
||||
memmove(Depot + remove_index, Depot + remove_index + 1, (sizeof(Depot) - remove_index - 1) * sizeof(*Depot));
|
||||
top--;
|
||||
}
|
||||
|
||||
time_t get_random_time()
|
||||
{
|
||||
time_t currentTime;
|
||||
|
||||
time(¤tTime);
|
||||
|
||||
long currentTimeNumber = (long)localtime(¤tTime);
|
||||
|
||||
// Random in next 5 hours
|
||||
long randomAddOnTime = rand() % (60 * 60 * 5);
|
||||
|
||||
long additionTime = currentTimeNumber + randomAddOnTime;
|
||||
|
||||
return additionTime;
|
||||
}
|
||||
|
||||
void clrscr()
|
||||
{
|
||||
system("clear");
|
||||
}
|
||||
|
||||
void confirm_on_finish()
|
||||
{
|
||||
|
||||
printf("\n\nPress Enter to Back to Menu...");
|
||||
|
||||
getchar();
|
||||
getchar();
|
||||
}
|
||||
|
||||
bool isFull()
|
||||
{
|
||||
return top == -1;
|
||||
}
|
||||
|
||||
int quicksort_compare_func(const void *elem1, const void *elem2)
|
||||
{
|
||||
struct Bus element1 = *((struct Bus *)elem1);
|
||||
struct Bus element2 = *((struct Bus *)elem2);
|
||||
if (element1.schedule > element2.schedule)
|
||||
return -1;
|
||||
if (element1.schedule < element2.schedule)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user