-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
1590 lines (1319 loc) · 40.8 KB
/
main.c
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************************************
Title : PROJECT GYRATE
Authors : 1.Praveen Naik
2.Prasad Patil
3.Prajwal Gouli
4.Prashant Roy
Start Date : 15 / 11 / 2019
End Date : 25 / 11 / 2019
University : KLE Technological University , Hubli
Guidance : Asst. Prof. Prakash Hegade
Purpose : To simulate the Cyclone attack scenario
***********************************************************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<malloc.h>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<stdbool.h>
#define SUCCESS 1
#define FAILURE -1
#define OUT_OF_INDEX -20
#define FILE_EMPTY_ERROR -30
struct cityDetails
{
char name[20];
//To store the name of the city
int elevation;
//To store the elevation of the city
int weatherStatus;
//City is in danger if weatherStatus=100
//City is not so safe if weatherStatus=50
//City is safe if weatherStatus=00
int population;
//To hold the current population of the city
int capacity;
//To hold the Maximum population of the city
int distance_from_sea;
//To hold distance from sea to city
int flag;
//To see if city is destroyed or not
int originalIndex;
//TO keep the old index after sorting
int med_facility;
//0-if no medical facility is available
//1-if medical facility is available
};
struct shortpath
{
int oriIndex;
//To keep the original index of the array after sorting
int distance;
//To keep the distance value
};
typedef struct cityDetails CITY;//Structure can be used by the name CITY
typedef struct shortpath PATH;
///{^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
///--------------------------------------------GLOBAL VARIABLES-----------------------------------------------------------
CITY cityData[40];//array of structures to hold the details of the cities
CITY TempData[40];//Backup file of cityData
int numofcity; //The number of cities
PATH shortpath[40];
int distance_matrix[40][40];//2d matrix to hold the distance between the cities
int totalPopulation=0;
int graph[40][40];
///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
///Function name : file_empty_check
//Input parameter: Filename (string)
//Description : It checks the size of the file and returns appropriate value
//Return type : Integer
//Return value : FILE_EMPTY_ERROR or SUCCESS
int file_empty_check(char *filename)
{
// Declaring "stat" a system call to know about content of file.
FILE* fp = fopen(filename, "r");
// checking if the file exist or not
if (fp == NULL) {
printf("File Not Found!\n");
return -1;
}
fseek(fp, 0L, SEEK_END);
// calculating the size of the file
long int res = ftell(fp);
// closing the file
fclose(fp);
//check size of file and return appropriate status.
if( res == 0 )
{
return FILE_EMPTY_ERROR;
}
else
{
return SUCCESS;
}
}
///Function name : Load_matrix
//Input parameter: NULL
//Description : Reads the input matrix from the file
//Return type :INT
//Return value : 1 or -1
int loadmatrix()
{
// Use a file pointer to open various files to load the values
FILE *fp;
//Local variables
int index = 0;
int row_index = 0;
int file_status = 0;
//check whether numofcity.txt file is empty or not.
file_status = file_empty_check("numofcity.txt");
if (file_status == -30)
{
printf("\nnumofcity file has no content\n");
return FAILURE;
}
//check whether distance_matrix.txt file is empty or not.
file_status = file_empty_check("distance_matrix.txt");
if (file_status == -30)
{
printf("\ndistance_matrix.txt file has no content\n");
return FAILURE;
}
// Open the numofcity.txt file to read the number of keywords
fp = fopen("numofcity.txt","r");
if(fp == NULL)
{
printf("\nnumofcity File opening error\n");
return FAILURE;
}
fscanf(fp,"%d", &numofcity);
if(numofcity <= 0 )
{
printf("\nNo. of cities can't be less than 1\n");
return FAILURE;
}
fclose(fp);
// Open the distance_matrix file to read the number of properties
fp = fopen("distance_matrix.txt","r");
if(fp == NULL)
{
printf("\nnumofcity File opening error\n");
return FAILURE;
}
// Load the details from file to main memory
while(!feof(fp)&&row_index<numofcity)
{
for(index = 0; index < numofcity; index++)
{
fscanf(fp, "%d",&distance_matrix[row_index][index]);
}
row_index++;//Increment row index;
}
fclose(fp);
//close the distance_matrix file
return SUCCESS;
}
///Function name :Load _city_names
//Input parameter:NULL
//Description : loads the city names from the file
//Return type : INT
//Return value : 1 or -1
int load_city_names()
{
// Use a file pointer to open various files to load the values
FILE *fp;
//Local variables
int row_index = 0;
int file_status = 0;
//check whether nameofcity.txt file is empty or not.
file_status = file_empty_check("nameofcity.txt");
if (file_status == -30)
{
printf("\nnameofcity file has no content\n");
return FAILURE;
}
// Open the nameofcity.txt file to read the number of keywords
fp = fopen("nameofcity.txt","r");
if(fp == NULL)
{
printf("\nnameofcity File opening error\n");
return FAILURE;
}
// Load the details from file to main memory
while(!feof(fp)&&row_index<numofcity)
{
fscanf(fp,"%s",cityData[row_index].name);
fscanf(fp,"%d",&cityData[row_index].population);
fscanf(fp,"%d",&cityData[row_index].capacity);
cityData[row_index].originalIndex=row_index;
cityData[row_index].flag=1;
totalPopulation+=cityData[row_index].population;
row_index++;//Increment row index;
}
fclose(fp);
//close the cityData file
return SUCCESS;
}
///Function name :Load_other_info
//Input parameter:NULL
//Description : Loads the other info about cities such as elevation and distance from the sea
//Return type : INT
//Return value : 1 or -1
int load_other_info()
{
// Use a file pointer to open various files to load the values
FILE *fp;
//Local variables
int row_index = 0;
int file_status = 0;
//check whether city_info.txt file is empty or not.
file_status = file_empty_check("city_info.txt");
if (file_status == -30)
{
printf("\ncity_info file has no content\n");
return FAILURE;
}
// Open the city_info.txt file to read the number of keywords
fp = fopen("city_info.txt","r");
if(fp == NULL)
{
printf("\ncity_info File opening error\n");
return FAILURE;
}
// Load the details from file to main memory
while(!feof(fp)&&row_index<numofcity)
{
fscanf(fp,"%d",&cityData[row_index].elevation);
fscanf(fp,"%d",&cityData[row_index].distance_from_sea);
row_index++;//Increment row index;
}
fclose(fp);
//close the cityData file
return SUCCESS;
}
///Function name :Load_weather_status
//Input parameter:NULL
//Description : it lodes the weather status of the cities
//Return type :INT
//Return value : 1 or -1
int load_weather_status()
{
// Use a file pointer to open various files to load the values
FILE *fp;
//Local variables
int row_index = 0;
int file_status = 0;
//check whether weather_status.txt file is empty or not.
file_status = file_empty_check("weather_status.txt");
if (file_status == -30)
{
printf("\nweather_status file has no content\n");
return FAILURE;
}
// Open the weather_status.txt file to read the number of keywords
fp = fopen("weather_status.txt","r");
if(fp == NULL)
{
printf("\nweather_status File opening error\n");
return FAILURE;
}
// Load the details from file to main memory
while(!feof(fp)&&row_index<numofcity)
{
fscanf(fp, "%d", &cityData[row_index].weatherStatus);
fscanf(fp,"%d",&cityData[row_index].med_facility);
row_index++;//Increment row index;
}
fclose(fp);
//close the weather_status file
return SUCCESS;
}
///Function name :dump
//Input parameter:NULL
//Description :It writes file the updated info of city
//Return type :INT
//Return value : 1 or -1
int dump()
{
// Local variables
int spec_index;
int row_index;
// File pointer
FILE *fp;
// Open the file in write mode and dump the latest key count
fp = fopen("numofcity.txt","w+");
if(fp == NULL) {
printf("\nnumofcity.txt File opening error\n");
return FAILURE;
}
fprintf(fp,"%d", numofcity);//write to file
fclose(fp);
//close the numofcity file
// Open the file in write mode and dump the latest properties count
fp = fopen("distance_matrix.txt","w+");
if(fp == NULL)
{
printf("\ndistance_matrix.txt File opening error\n");
return FAILURE;
}
for (spec_index = 0; spec_index <= numofcity; spec_index++)
{
for (row_index = 0; row_index <= numofcity; row_index++)
{
fprintf(fp, "%d ", distance_matrix[spec_index][row_index]);
}
fprintf(fp, "%s", "\n");
}
fclose(fp);
//close the distance_matrix file
//open the file in write mode and dump the latest city details
fp = fopen("nameofcity.txt","w+");
if(fp == NULL)
{
printf("\nnameof city.txt File opening error\n");
return FAILURE;
}
for (spec_index = 0; spec_index < numofcity; spec_index++)
{
fprintf(fp, "%s ", cityData[spec_index].name);
fprintf(fp, "%d ", cityData[spec_index].population);
fprintf(fp, "%d ", cityData[spec_index].capacity);
fprintf(fp, "%s", "\n");
}
fclose(fp);
//close the nameofcity file
//open the file in write mode and dump the latest weather status
fp = fopen("weather_status.txt","w+");
if(fp == NULL)
{
printf("\nweather_status.txt File opening error\n");
return FAILURE;
}
for (spec_index = 0; spec_index <= numofcity; spec_index++)
{
fprintf(fp, "%d ", cityData[spec_index].weatherStatus);
fprintf(fp, "%d ", cityData[spec_index].med_facility);
fprintf(fp, "%s", "\n");
}
fclose(fp);
//close the weather_status file
return SUCCESS;
}
///Function name :printmatrix
//Input parameter:NULL
//Description : Prints the distance matrix of cities
//Return type :NULL
//Return value :NULL
void printmatrix()
{
//Empty check
if(numofcity<=0)
{
printf("\nNo data added yet\n");
return;
}
printf("\n");
for(int i=0;i<numofcity;i++)
{
for(int j=0;j<numofcity;j++)
{
printf("%4d ",distance_matrix[i][j]);
}
printf("\n");
}
}
///Function name :printcity
//Input parameter:citydata
//Description : Prints the info of city
//Return type : void
//Return value :NULL
void printcity(CITY cityData[])
{
//Empty check
if(numofcity<=0)
{
printf("\nNo data added yet\n");
return;
}
printf("\nindex - City name\tpopulation\tcapacity\tweather\t\televation\tdistance from sea\tMedical facility\n");
for(int i=0;i<numofcity;i++)
{
printf("%d - %15s\t%d\t\t%d\t\t%d\t\t%d\t\t%d\t\t\t%d\n",i,cityData[i].name,cityData[i].population,cityData[i].capacity,cityData[i].weatherStatus,cityData[i].elevation,cityData[i].distance_from_sea,cityData[i].med_facility);
}
printf("\nNOTE :\n1- medical facility available\n0-no medical facility available\n2-medical facility is supplied by other cities\n");
printf("\n***weather status****\n0-no danger\n50-moderate danger\n100-most dangerous \n");
}
///Function name :menu1
//Input parameter:NULL
//Description : prints the menu of the program for the user
//Return type : NULL
//Return value : NULL
void menu1()
{
printf("\n*************MENU****************\n");
printf("\n404.dump and exit\n");
printf("1.print matrix\n");
printf("2.print city details\n");
printf("3.print duplicate\n");
printf("4.show the nearest city to Sea \n");
printf("5.search by city name\n");
printf("-1.NEXT LEVEL\n");
}
///Function name :menu2
//Input parameter:NULL
//Description : prints the menu of the program for the user
//Return type : NULL
//Return value : NULL
void menu2()
{
printf("\n*************MENU****************\n");
printf("\n404.dump and exit\n");
printf("1.print matrix\n");
printf("2.print city details\n");
printf("3.print duplicate\n");
printf("4.GIVE A CYCLONE ALERT AND Update weather status by weather_status file\n");
printf("5.search by city name\n");
printf("6.show the cyclone affected cites in order\n");
printf("7.sort the cites according to elevation and bad weather\n and evacuate them\n");
printf("8.show the safe and destroyed city list\n");
printf("9.Provide the medical facility to affected cities\n");
printf("10.show the death count\n");
printf("-1.NEXT LEVEL");
}
///Function name :menu3
//Input parameter:NULL
//Description : prints the menu of the program for the user
//Return type : NULL
//Return value : NULL
void menu3()
{
printf("\n*************MENU****************\n");
printf("\n404.dump and exit\n");
printf("1.print matrix\n");
printf("2.print city details\n");
printf("3.print duplicate\n");
printf("4.search by city name\n");
printf("5.Show the destroyed cities and recover them\n");
printf("6.Show the shortest path for officers to visit all the cities\n");
printf("7.Alternative Solution or precautions to prevent cyclone losses..\n ");
printf("-1.Exit\n");
}
///Function name : printspecific
//Input parameter: index of city's info
//Description : prints the info of given city
//Return type : NULL
//Return value : NULL
void printspecific(int i)
{
if(i>=numofcity||i<0)
{
printf("\nIndex out of order \n");
return;
}
printf("\nindex - City name\tpopulation\tcapacity\tweather\t\televation\tdistance from sea Medical facility\n");
printf("%d - %15s\t%d\t\t%d\t\t%d\t\t%d\t\t%d\t\t\t%d\n",i,cityData[i].name,cityData[i].population,cityData[i].capacity,cityData[i].weatherStatus,cityData[i].elevation,cityData[i].distance_from_sea,cityData[i].med_facility);
printf("\nNOTE :\n1- medical facility available\n0-no medical facility available\n2-medical facility is supplied by other cities\n");
printf("\n***weather status****\n0-no danger\n50-moderate danger\n100-most dangerous \n");
}
///Function name :printonlycity
//Input parameter: city data
//Description : gives the description of the ciy
//Return type : NULL
//Return value : NULL
void printonlycity(CITY cityData[])
{
//Empty check
if(numofcity<=0)
{
printf("\nNo data added yet\n");
return;
}
printf("\nindex - City name\tdistance from sea\n");
for(int i=0;i<numofcity;i++)
{
printf("%d - %15s\t%d\n",i,cityData[i].name,cityData[i].distance_from_sea);
}
}
void printonlycity2(CITY cityData[])
{
//Empty check
if(numofcity<=0)
{
printf("\nNo data added yet\n");
return;
}
printf("\nindex - City name\tElevation\n");
for(int i=0;i<numofcity;i++)
{
printf("%d - %15s\t%d\n",i,cityData[i].name,cityData[i].elevation);
}
}
///Function name :search
//Input parameter: name of city
//Description : searchs the city in the file
//Return type : INT
//Return value : 1 or -1
int search(char s[])
{
int i;
for(i=0;i<numofcity;i++)
{
//comparing given string to city names
if(strcmp(cityData[i].name,s)==0)
return i;//return index of city
}
return FAILURE;
}
///Function name :dijkstras
//Input parameter:number of cities and source city
//Description :to find the shortest distance from the source city to every
// other cities
//Return type : void
//Return value : NULL
void dijkstras(int v,int source)
{
///Local variable
int visited[40];
int queue[40];
int i;
int j;
int front=0;
int rear=0;
int u;
int sum;
//initializing visited array and shortpath distance
for(i=0;i<=v;i++)
{
visited[i]=0;
shortpath[i].distance=INT_MAX;
shortpath[i].oriIndex=i;
}
visited[source]=1;
queue[rear]=source;
shortpath[source].distance=0;
for(i=0;i<v;i++)
{
u=queue[front];
front++;
for(j=0;j<v;j++)
{
if(distance_matrix[u][j]!=0)
{
if(visited[j]==0)
{
rear++;
queue[rear]=j;
}
sum=shortpath[u].distance+distance_matrix[u][j];
if(sum<shortpath[j].distance)
{
shortpath[j].distance=sum;
;
}
visited[u]=1;//mark the city as visited
}
}
}
}
///Function name :Merge2
//Input parameter: distance from sea
//Description : sorts the cities as per the distance from the sea.
//Return type :NULL
//Return value :NULL
void Merge2(PATH b[50],int p,PATH c[50],int q,PATH a[50])
{
int i=0,j=0,k=0;
while(i<p&&j<q)
{
if(b[i].distance<=c[j].distance)
{
a[k]=b[i];
i++;
}
else
{
a[k]=c[j];
j++;
}
k++;
}
if(i==p)
{
for(i=j;i<q;i++)
{
a[k]=c[i];
k++;
}
}
else
for(j=i;j<p;j++)
{
a[k]=b[j];
k++;
}
}
///Function name :MergeSort2
//Input parameter: distance from sea
//Description : sorts the cities as per the distance from the sea.
//Return type :NULL
//Return value :NULL
void MergeSort2(PATH a[50],int n)
{
if(n>1)
{
int i;
PATH b[100],c[100];
for(i=0;i<(n/2);i++)
{
b[i]=a[i];
}
int k=0;
for(i=n/2;i<n;i++)
{
c[k]=a[i];
k++;
}
MergeSort2(b,n/2);
MergeSort2(c,k);
Merge2(b,n/2,c,k,a);
}
}
///Function name :movetosafe
//Input parameter:an integer number
//Description :This function basically moves the population of cites which are in danger zone to a safe city
//Return type :integer
//Return value :1 or -1
int movetosafe(int num)
{
int j=0,i ;
if(num>=numofcity)
return FAILURE;
while(j != num)
{
dijkstras(numofcity,TempData[j].originalIndex);
MergeSort2(shortpath,numofcity);
for(i = 1;i < numofcity&&TempData[j].population;i++)
{
if(TempData[cityData[shortpath[i].oriIndex].originalIndex].flag&&TempData[cityData[shortpath[i].oriIndex].originalIndex].population<TempData[cityData[shortpath[i].oriIndex].originalIndex].capacity)
{
TempData[cityData[shortpath[i].oriIndex].originalIndex].population+=TempData[j].population;
if(TempData[cityData[shortpath[i].oriIndex].originalIndex].population>TempData[cityData[shortpath[i].oriIndex].originalIndex].capacity)
{
TempData[j].population=TempData[cityData[shortpath[i].oriIndex].originalIndex].population-TempData[cityData[shortpath[i].oriIndex].originalIndex].capacity;
TempData[cityData[shortpath[i].oriIndex].originalIndex].population=TempData[cityData[shortpath[i].oriIndex].originalIndex].capacity;
}
else
{
TempData[j].population=0;
TempData[j].flag=0;
}
}
}
if(i >= numofcity)
{
TempData[j].flag=0;
return FAILURE;
}
j++;
}
return SUCCESS;
}
///Function name :Merge1
//Input parameter:City name
//Description :sorts the city as per the city name
//Return type :NULL
//Return value :NULL
void Merge1(CITY b[50],int p,CITY c[50],int q,CITY a[50])
{
int i=0,j=0,k=0;
while(i<p&&j<q)
{
if(b[i].distance_from_sea<=c[j].distance_from_sea)
{
a[k]=b[i];
i++;
}
else
{
a[k]=c[j];
j++;
}
k++;
}
if(i==p)
{
for(i=j;i<q;i++)
{
a[k]=c[i];
k++;
}
}
else
for(j=i;j<p;j++)
{
a[k]=b[j];
k++;
}
}
///Function name :MergeSort1
//Input parameter:City name
//Description :sorts the city as per the city name
//Return type :NULL
//Return value :NULL
void MergeSort1(CITY a[50],int n)
{
if(n>1)
{
int i;
CITY b[100],c[100];
for(i=0;i<(n/2);i++)
{
b[i]=a[i];
}
int k=0;
for(i=n/2;i<n;i++)
{
c[k]=a[i];
k++;
}
MergeSort1(b,n/2);
MergeSort1(c,k);
Merge1(b,n/2,c,k,a);
}
}
int partition(CITY a[],int x,int y)
{
//Local Variables
CITY temp;
int p=a[x].weatherStatus;
int i=x;
int j=y+1;
do
{
do
{
i=i+1;
}while(((a[i].weatherStatus)>(p))&&(i<numofcity));
do
{
j=j-1;
} while((a[j].weatherStatus)<(p)&&j!=-1);
temp=a[i];
a[i]=a[j];
a[j]=temp;
}while(i<j);
temp=a[i];
a[i]=a[j];
a[j]=temp;
temp=a[x];
a[x]=a[j];
a[j]=temp;
return j;
}
///Function name :quickSort
//Input parameter:City name
//Description :This function sorts the city based o their city names
//Return type :NULL
//Return value :NULL
void quickSort(CITY a[],int l,int r)
{
if(l<r)
{
int s=partition(a,l,r);
quickSort(a,l,s-1);
quickSort(a,s+1,r);
}
}
///Function name :bad_weather
//Input parameter: city name
//Description : sorts the cities as per the weather condition
//Return type : NULL
//Return value : NULL
void bad_weather(CITY city[])
{
quickSort(city,0,numofcity-1);
printcity(city);
}
///Function name :update_Original
//Input parameter:NULL
//Description : updates the original info of city
//Return type :NULL
//Return value :NULL
void update_Original()
{
for(int i=0;i<numofcity;i++)
{
cityData[TempData[i].originalIndex].flag=TempData[i].flag;
cityData[TempData[i].originalIndex].population=TempData[i].population;
cityData[i].originalIndex=TempData[cityData[i].originalIndex].originalIndex;
}
}
///Function name :update_temp
//Input parameter:NULL
//Description :This function updates the med facility and weather status
//Return type :NULL
//Return value :NULL
void update_temp()
{
for(int i=0;i<numofcity;i++)
{
TempData[TempData[i].originalIndex].weatherStatus=cityData[i].weatherStatus;
TempData[TempData[i].originalIndex].med_facility=cityData[i].med_facility;
}
}
///Function name :check_for_death
//Input parameter:NULL
//Description :This function counts the death during the calamity
//Return type :NULL
//Return value :NULL
void check_for_death()
{
int sum=0;
for(int i=0;i<numofcity;i++)
{
sum+=cityData[i].population;
}
if(sum==totalPopulation)
{
printf("\nDue to Proper precaution and planning no death is happened till now!!!!\n");
}
else
printf("\nDeath count till now = %d \n",totalPopulation-sum);