-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem21.c
More file actions
57 lines (45 loc) · 1.11 KB
/
Copy pathproblem21.c
File metadata and controls
57 lines (45 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_APPOINTMENTS 100000
#define MAX_LINE_LENGTH 1000000
void zigZagReorder(int appointments[], int n){
int result[n];
int start = 0, end = n - 1, index = 0;
while(start <= end){
if(start == end){
result[index++] = appointments[start++];
}
else{
result[index++] = appointments[start++];
result[index++] = appointments[end--];
}
}
printf("Reordered Appointments in Zig-Zag Pattern:\n");
for(int i = 0; i < n; i++){
printf("%d", result[i]);
if(i < n - 1) printf(", ");
}
printf("\n");
}
int main(){
int appointments[MAX_APPOINTMENTS];
int n = 0;
char line[MAX_LINE_LENGTH];
printf("Enter appointment IDs: ");
if(fgets(line, sizeof(line), stdin) == NULL || line[0] == '\n'){
printf("No appointments entered\n");
return 1;
}
char *token = strtok(line, " \n");
while(token != NULL){
appointments[n++] = atoi(token);
token = strtok(NULL, " \n");
}
if(n == 0){
printf("!! Invalid Input !!\n");
return 1;
}
zigZagReorder(appointments, n);
return 0;
}