-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDS Assignment 02.cpp
More file actions
906 lines (764 loc) · 17.9 KB
/
DS Assignment 02.cpp
File metadata and controls
906 lines (764 loc) · 17.9 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
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
#include<iostream>
#include<time.h>
#include<cstdlib>
#include<fstream>
using namespace std;
//Prototypes
void merge(int arr[],int lb,int mid,int ub);
int MedianOfThreePartition(int arr[],int p, int r);
int Updated_MedianOfThree_Partition(int arr[],int p,int r);
//Global variable (i.e used in Quick-II/III)
int count=0;
//Sorting Algorithms
void Insertion_Sort(int arr[],int size)
{
for(int i=1;i<size;i++)
{
int temp;
temp=arr[i];
int j=i-1;
while(j>=0 && arr[j]>temp)
{
arr[j+1]=arr[j];
j--;
}
arr[j+1]=temp;
}
}
void merge(int arr[], int lb, int mid, int ub) // lb - lower bound(start)
{ // ub - upper bound (end)
int i,j,k,nl,nr; // mid - middle value
nl = mid-lb+1; nr = ub-mid;
int larr[nl], rarr[nr];
for(i = 0; i<nl; i++)
{
larr[i] = arr[lb+i];
}
for(j = 0; j<nr; j++)
{
rarr[j] = arr[mid+1+j];
}
i = 0; j = 0; k = lb;
while(i < nl && j<nr) {
if(larr[i] <= rarr[j]) {
arr[k] = larr[i];
i++;
}else{
arr[k] = rarr[j];
j++;
}
k++;
}
while(i<nl) { //extra element in left array
arr[k] = larr[i];
i++; k++;
}
while(j<nr) { //extra element in right array
arr[k] = rarr[j];
j++; k++;
}
}
void Merge_Sort(int arr[], int lb, int ub)
{
if(lb < ub) {
//int mid = lb+(ub-lb)/2;
int mid = (lb+ub)/2;
// Sort first and second arrays
Merge_Sort(arr, lb, mid);
Merge_Sort(arr, mid+1, ub);
merge(arr, lb, mid, ub);
}
}
int Partition(int arr[],int lb,int ub)
{
int pivot=arr[lb]; //Random number of array as pivot (i.e first value of array)
int start=lb;
int end=ub;
while(start<end)
{
while(arr[start]<=pivot)
{
start++;
}
while(arr[end]>pivot)
{
end--;
}
if(start<end)
{
swap(arr[start],arr[end]);
}
}
swap(arr[lb],arr[end]);
return end;
}
int Quick_Sort_RandomPivot(int arr[],int lb,int ub)
{
if(lb<ub)
{
int location=Partition(arr,lb,ub);
Quick_Sort_RandomPivot(arr,lb,location-1);
Quick_Sort_RandomPivot(arr,location+1,ub);
}
}
void Quick_Sort_MiddlePivot(int arr[], int lb, int ub) {
int start = lb, end = ub;
int temp;
int pivot = arr[(lb + ub) / 2];
/* partition */
while (start <= end) {
while (arr[start] < pivot)
{
start++;
}
while (arr[end] > pivot)
{
end--;
}
if (start <= end)
{
temp=arr[start];
arr[start]=arr[end];
arr[end]=temp;
start++;
end--;
}
}
/* recursion */
if (lb < end)
{
Quick_Sort_MiddlePivot(arr, lb, end);
}
if (start < ub)
{
Quick_Sort_MiddlePivot(arr, start, ub);
}
}
void Quick_Sort_MedianPivot(int arr[],int start,int end)
{
int med;
count++;
if (end-start<2)
return;
med=MedianOfThreePartition(arr,start,end);
Quick_Sort_MedianPivot(arr,start,med);
Quick_Sort_MedianPivot(arr,med,end);
}
int MedianOfThreePartition(int arr[],int p, int r)
{
int x=arr[p];
int y=arr[(r-p)/2+p];
int z=arr[r-1];
int i=p-1,j=r;
if (y>x && y<z || y>z && y<x )
{
x=y;
}
else if (z>x && z<y || z>y && z<x )
{
x=z;
}
while (1) {
do {j--;count++;} while (arr[j] > x);
do {i++;count++;} while (arr[i] < x);
if (i < j)
{
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
else return j+1;
}
}
void Quick_Sort_UpdatedMedianPivot(int arr[],int start,int end)
{
int med;
count++;
if (end-start<2)
return;
med=Updated_MedianOfThree_Partition(arr,start,end);
Quick_Sort_UpdatedMedianPivot(arr,start,med);
Quick_Sort_UpdatedMedianPivot(arr,med,end);
}
int Updated_MedianOfThree_Partition(int arr[],int p, int r)
{
int x=arr[p];
int y=arr[(r-p)/2+p];
int z=arr[r-1];
int i=p-1,j=r;
if (y>x && y<z || y>z && y<x )
{
x=y;
}
else if (z>x && z<y || z>y && z<x )
{
x=z;
}
while (1) {
do {j--;count++;} while (arr[j] > x);
do {i++;count++;} while (arr[i] < x);
if (i < j)
{
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
else return j+1;
}
}
int main()
{
//FILE 1 FOR HANDLING 50 NUMBERS
ofstream o1("D:\\check1.txt");
int i;
bool arr1[50]={0};
int s_arr1[50];
time_t t1;
srand((unsigned)time(&t1));
cout<<"50 NUMBERS: "<<endl;
for(i=0;i<50;++i)
{
int r1=rand()%50;
if(!arr1[r1])
{
s_arr1[i]=r1;
o1<<r1<<endl;
cout<<s_arr1[i]<<endl;
}
else
i--;
arr1[r1]=1;
}
o1.close();
cout<<"\n\n\n\n\n SORTED 50 NUMBERS (INSERTION SORT)"<<endl;
o1.open("D:\\check1.txt");
Insertion_Sort(s_arr1,50);
for(int i=0;i<50;i++)
{
o1<<s_arr1[i]<<endl;
cout<<s_arr1[i]<<endl;
}
o1.close();
cout<<"\n\n\n\n\n SORTED 50 NUMBERS (MERGE SORT)"<<endl;
o1.open("D:\\check1.txt");
Merge_Sort(s_arr1,0,49);
for(int i=0;i<50;i++)
{
o1<<s_arr1[i]<<endl;
cout<<s_arr1[i]<<endl;
}
o1.close();
//(QUICK)
cout<<"\n\n\n\n\n SORTED 50 NUMBERS (QUICK SORT | MIDDLE PIVOT)"<<endl;
o1.open("D:\\check1.txt");
Quick_Sort_MiddlePivot(s_arr1,0,49);
for(int i=0;i<50;i++)
{
o1<<s_arr1[i]<<endl;
cout<<s_arr1[i]<<endl;
}
o1.close();
//(QUICK I)
cout<<"\n\n\n\n\n SORTED 50 NUMBERS (QUICK SORT | RANDOM PIVOT)"<<endl;
o1.open("D:\\check1.txt");
Quick_Sort_RandomPivot(s_arr1,0,49);
for(int i=0;i<50;i++)
{
o1<<s_arr1[i]<<endl;
cout<<s_arr1[i]<<endl;
}
o1.close();
//(QUICK II)
cout<<"\n\n\n\n\n SORTED 50 NUMBERS (QUICK SORT | MEDIAN PIVOT)"<<endl;
o1.open("D:\\check1.txt");
Quick_Sort_MedianPivot(s_arr1,0,50);
for(int i=0;i<50;i++)
{
o1<<s_arr1[i]<<endl;
cout<<s_arr1[i]<<endl;
}
o1.close();
//(QUICK III)
cout<<"\n\n\n\n\n SORTED 50 NUMBERS (QUICK SORT | UPDATED MEDIAN PIVOT)"<<endl;
o1.open("D:\\check1.txt");
Quick_Sort_UpdatedMedianPivot(s_arr1,0,50);
for(int i=0;i<50;i++)
{
o1<<s_arr1[i]<<endl;
cout<<s_arr1[i]<<endl;
}
o1.close();
//FILE 2 FOR HANDLING 100 NUMBERS
ofstream o2("D:\\check2.txt");
bool arr2[100]={0};
int s_arr2[100];
time_t t2;
srand((unsigned)time(&t2));
cout<<"\n\n\n 100 NUMBERS: "<<endl;
for(i=0;i<100;++i)
{
int r2=rand()%100;
if(!arr2[r2])
{
s_arr2[i]=r2;
o2<<r2<<endl;
cout<<s_arr2[i]<<endl;
}
else
i--;
arr2[r2]=1;
}
o2.close();
cout<<"\n\n\n\n\n SORTED 100 NUMBERS (INSERTION SORT)"<<endl;
o2.open("D:\\check2.txt");
Insertion_Sort(s_arr2,100);
for(int i=0;i<100;i++)
{
o2<<s_arr2[i]<<endl;
cout<<s_arr2[i]<<endl;
}
o2.close();
cout<<"\n\n\n\n\n SORTED 100 NUMBERS (MERGE SORT)"<<endl;
o2.open("D:\\check2.txt");
Merge_Sort(s_arr2,0,99);
for(int i=0;i<100;i++)
{
o2<<s_arr2[i]<<endl;
cout<<s_arr2[i]<<endl;
}
o2.close();
//(QUICK)
cout<<"\n\n\n\n\n SORTED 100 NUMBERS (QUICK SORT | MIDDLE PIVOT)"<<endl;
o2.open("D:\\check2.txt");
Quick_Sort_MiddlePivot(s_arr2,0,99);
for(int i=0;i<100;i++)
{
o2<<s_arr2[i]<<endl;
cout<<s_arr2[i]<<endl;
}
o2.close();
// (QUICK I)
cout<<"\n\n\n\n\n SORTED 100 NUMBERS (QUICK SORT | RANDOM PIVOT)"<<endl;
o2.open("D:\\check2.txt");
Quick_Sort_RandomPivot(s_arr2,0,99);
for(int i=0;i<100;i++)
{
o2<<s_arr2[i]<<endl;
cout<<s_arr2[i]<<endl;
}
o2.close();
//(QUICK II)
cout<<"\n\n\n\n\n SORTED 100 NUMBERS (QUICK SORT | MEDIAN PIVOT)"<<endl;
o2.open("D:\\check2.txt");
Quick_Sort_MedianPivot(s_arr2,0,100);
for(int i=0;i<100;i++)
{
o2<<s_arr2[i]<<endl;
cout<<s_arr2[i]<<endl;
}
o2.close();
//(QUICK III)
cout<<"\n\n\n\n\n SORTED 100 NUMBERS (QUICK SORT | UPDATED MEDIAN PIVOT)"<<endl;
o2.open("D:\\check2.txt");
Quick_Sort_UpdatedMedianPivot(s_arr2,0,100);
for(int i=0;i<100;i++)
{
o2<<s_arr2[i]<<endl;
cout<<s_arr2[i]<<endl;
}
o2.close();
//FILE 3 FOR HANDLING 200 NUMBERS
ofstream o3("D:\\check3.txt");
bool arr3[200]={0};
int s_arr3[200];
time_t t3;
srand((unsigned)time(&t3));
cout<<"\n\n\n 200 NUMBERS: "<<endl;
for(i=0;i<200;++i)
{
int r3=rand()%200;
if(!arr3[r3])
{
s_arr3[i]=r3;
o3<<r3<<endl;
cout<<s_arr3[i]<<endl;
}
else
i--;
arr3[r3]=1;
}
o3.close();
cout<<"\n\n\n\n\n SORTED 200 NUMBERS (INSERTION SORT)"<<endl;
o3.open("D:\\check3.txt");
Insertion_Sort(s_arr3,200);
for(int i=0;i<200;i++)
{
o3<<s_arr3[i]<<endl;
cout<<s_arr3[i]<<endl;
}
o3.close();
cout<<"\n\n\n\n\n SORTED 200 NUMBERS (MERGE SORT)"<<endl;
o3.open("D:\\check3.txt");
Merge_Sort(s_arr3,0,199);
for(int i=0;i<200;i++)
{
o3<<s_arr3[i]<<endl;
cout<<s_arr3[i]<<endl;
}
o3.close();
cout<<"\n\n\n\n\n SORTED 200 NUMBERS (QUICK SORT | MIDDLE PIVOT)"<<endl;
o3.open("D:\\check3.txt");
Quick_Sort_MiddlePivot(s_arr3,0,199);
for(int i=0;i<200;i++)
{
o3<<s_arr3[i]<<endl;
cout<<s_arr3[i]<<endl;
}
o3.close();
//QUICK I
cout<<"\n\n\n\n\n SORTED 200 NUMBERS (QUICK SORT | RANDOM PIVOT)"<<endl;
o3.open("D:\\check3.txt");
Quick_Sort_RandomPivot(s_arr3,0,199);
for(int i=0;i<200;i++)
{
o3<<s_arr3[i]<<endl;
cout<<s_arr3[i]<<endl;
}
o3.close();
//QUICK II
cout<<"\n\n\n\n\n SORTED 200 NUMBERS (QUICK SORT | MEDIAN PIVOT)"<<endl;
o3.open("D:\\check3.txt");
Quick_Sort_MedianPivot(s_arr3,0,200);
for(int i=0;i<200;i++)
{
o3<<s_arr3[i]<<endl;
cout<<s_arr3[i]<<endl;
}
o3.close();
// (QUICK III)
cout<<"\n\n\n\n\n SORTED 200 NUMBERS (QUICK SORT | UPDATED MEDIAN PIVOT)"<<endl;
o3.open("D:\\check3.txt");
Quick_Sort_UpdatedMedianPivot(s_arr3,0,200);
for(int i=0;i<200;i++)
{
o3<<s_arr3[i]<<endl;
cout<<s_arr3[i]<<endl;
}
o3.close();
//FILE 4 FOR HANDLING 300 NUMBERS
ofstream o4("D:\\check4.txt");
bool arr4[300]={0};
int s_arr4[300];
time_t t4;
srand((unsigned)time(&t4));
cout<<"\n\n\n 300 NUMBERS: "<<endl;
for(i=0;i<300;++i)
{
int r4=rand()%300;
if(!arr4[r4])
{
s_arr4[i]=r4;
o4<<r4<<endl;
cout<<s_arr4[i]<<endl;
}
else
i--;
arr4[r4]=1;
}
o4.close();
cout<<"\n\n\n\n\n SORTED 300 NUMBERS (INSERTION SORT)"<<endl;
o4.open("D:\\check4.txt");
Insertion_Sort(s_arr4,300);
for(int i=0;i<300;i++)
{
o4<<s_arr4[i]<<endl;
cout<<s_arr4[i]<<endl;
}
o4.close();
cout<<"\n\n\n\n\n SORTED 300 NUMBERS (MERGE SORT)"<<endl;
o4.open("D:\\check4.txt");
Merge_Sort(s_arr4,0,299);
for(int i=0;i<300;i++)
{
o4<<s_arr4[i]<<endl;
cout<<s_arr4[i]<<endl;
}
o4.close();
//QUICK
cout<<"\n\n\n\n\n SORTED 300 NUMBERS (QUICK SORT | MIDDLE PIVOT)"<<endl;
o4.open("D:\\check4.txt");
Quick_Sort_MiddlePivot(s_arr4,0,299);
for(int i=0;i<300;i++)
{
o4<<s_arr4[i]<<endl;
cout<<s_arr4[i]<<endl;
}
o4.close();
//QUICK I
cout<<"\n\n\n\n\n SORTED 300 NUMBERS (QUICK SORT | RANDOM PIVOT)"<<endl;
o4.open("D:\\check4.txt");
Quick_Sort_RandomPivot(s_arr4,0,299);
for(int i=0;i<300;i++)
{
o4<<s_arr4[i]<<endl;
cout<<s_arr4[i]<<endl;
}
o4.close();
// QUICK II
cout<<"\n\n\n\n\n SORTED 300 NUMBERS (QUICK SORT | MEDIAN PIVOT)"<<endl;
o4.open("D:\\check4.txt");
Quick_Sort_MedianPivot(s_arr4,0,300);
for(int i=0;i<300;i++)
{
o4<<s_arr4[i]<<endl;
cout<<s_arr4[i]<<endl;
}
o4.close();
// (QUICK III)
cout<<"\n\n\n\n\n SORTED 300 NUMBERS (QUICK SORT | UPDATED MEDIAN PIVOT)"<<endl;
o4.open("D:\\check4.txt");
Quick_Sort_UpdatedMedianPivot(s_arr4,0,300);
for(int i=0;i<300;i++)
{
o4<<s_arr4[i]<<endl;
cout<<s_arr4[i]<<endl;
}
o4.close();
//FILE 5 HANDLING 400 NUMBERS
ofstream o5("D:\\check5.txt");
bool arr5[400]={0};
int s_arr5[400];
time_t t5;
srand((unsigned)time(&t5));
cout<<"\n\n\n 400 NUMBERS: "<<endl;
for(i=0;i<400;++i)
{
int r5=rand()%400;
if(!arr5[r5])
{
s_arr5[i]=r5;
o5<<r5<<endl;
cout<<s_arr5[i]<<endl;
}
else
i--;
arr5[r5]=1;
}
o5.close();
cout<<"\n\n\n\n\n SORTED 400 NUMBERS (INSERTION SORT)"<<endl;
o5.open("D:\\check5.txt");
Insertion_Sort(s_arr5,400);
for(int i=0;i<400;i++)
{
o4<<s_arr5[i]<<endl;
cout<<s_arr5[i]<<endl;
}
o5.close();
cout<<"\n\n\n\n\n SORTED 400 NUMBERS (MERGE SORT)"<<endl;
o5.open("D:\\check5.txt");
Merge_Sort(s_arr5,0,399);
for(int i=0;i<400;i++)
{
o5<<s_arr5[i]<<endl;
cout<<s_arr5[i]<<endl;
}
o5.close();
//QUICK
cout<<"\n\n\n\n\n SORTED 400 NUMBERS (QUICK SORT | MIDDLE PIVOT)"<<endl;
o5.open("D:\\check5.txt");
Quick_Sort_MiddlePivot(s_arr5,0,399);
for(int i=0;i<400;i++)
{
o5<<s_arr5[i]<<endl;
cout<<s_arr5[i]<<endl;
}
o5.close();
//QUICK I
cout<<"\n\n\n\n\n SORTED 400 NUMBERS (QUICK SORT | RANDOM PIVOT)"<<endl;
o5.open("D:\\check5.txt");
Quick_Sort_RandomPivot(s_arr5,0,399);
for(int i=0;i<400;i++)
{
o5<<s_arr5[i]<<endl;
cout<<s_arr5[i]<<endl;
}
o5.close();
// QUICK II
cout<<"\n\n\n\n\n SORTED 400 NUMBERS (QUICK SORT | MEDIAN PIVOT)"<<endl;
o5.open("D:\\check5.txt");
Quick_Sort_MedianPivot(s_arr5,0,400);
for(int i=0;i<400;i++)
{
o5<<s_arr5[i]<<endl;
cout<<s_arr5[i]<<endl;
}
o5.close();
// (QUICK III)
cout<<"\n\n\n\n\n SORTED 400 NUMBERS (QUICK SORT | UPDATED MEDIAN PIVOT)"<<endl;
o5.open("D:\\check5.txt");
Quick_Sort_UpdatedMedianPivot(s_arr5,0,400);
for(int i=0;i<400;i++)
{
o5<<s_arr5[i]<<endl;
cout<<s_arr5[i]<<endl;
}
o5.close();
//FILE 6 FOR HANDLING 500 NUMBERS
ofstream o6("D:\\check6.txt");
bool arr6[500]={0};
int s_arr6[500];
time_t t6;
srand((unsigned)time(&t6));
//cout<<"\n\n\n 500 NUMBERS: "<<endl;
for(i=0;i<500;++i)
{
int r6=rand()%500;
if(!arr6[r6])
{
s_arr6[i]=r6;
o6<<r6<<endl;
//cout<<s_arr6[i]<<endl;
}
else
i--;
arr6[r6]=1;
}
o6.close();
//cout<<"\n\n\n\n\n SORTED 500 NUMBERS (INSERTION SORT)"<<endl;
o6.open("D:\\check6.txt");
Insertion_Sort(s_arr6,500);
for(int i=0;i<500;i++)
{
o6<<s_arr6[i]<<endl;
//cout<<s_arr6[i]<<endl;
}
o6.close();
//cout<<"\n\n\n\n\n SORTED 500 NUMBERS (MERGE SORT)"<<endl;
o6.open("D:\\check6.txt");
Merge_Sort(s_arr6,0,499);
for(int i=0;i<500;i++)
{
o6<<s_arr6[i]<<endl;
//cout<<s_arr6[i]<<endl;
}
o6.close();
//QUICK
//cout<<"\n\n\n\n\n SORTED 500 NUMBERS (QUICK SORT | MIDDLE PIVOT)"<<endl;
o6.open("D:\\check6.txt");
Quick_Sort_MiddlePivot(s_arr6,0,499);
for(int i=0;i<500;i++)
{
o6<<s_arr6[i]<<endl;
//cout<<s_arr6[i]<<endl;
}
o6.close();
//QUICK I
//cout<<"\n\n\n\n\n SORTED 500 NUMBERS (QUICK SORT | RANDOM PIVOT)"<<endl;
o6.open("D:\\check6.txt");
Quick_Sort_RandomPivot(s_arr6,0,499);
for(int i=0;i<500;i++)
{
o6<<s_arr6[i]<<endl;
//cout<<s_arr6[i]<<endl;
}
o6.close();
//QUICK II
//cout<<"\n\n\n\n\n SORTED 500 NUMBERS (QUICK SORT | MEDIAN PIVOT)"<<endl;
o6.open("D:\\check6.txt");
Quick_Sort_MedianPivot(s_arr6,0,500);
for(int i=0;i<500;i++)
{
o6<<s_arr6[i]<<endl;
//cout<<s_arr6[i]<<endl;
}
o6.close();
// (QUICK III)
//cout<<"\n\n\n\n\n SORTED 500 NUMBERS (QUICK SORT | UPDATED MEDIAN PIVOT)"<<endl;
o6.open("D:\\check6.txt");
Quick_Sort_UpdatedMedianPivot(s_arr6,0,500);
for(int i=0;i<500;i++)
{
o6<<s_arr6[i]<<endl;
//cout<<s_arr6[i]<<endl;
}
o6.close();
//FILE 7 FOR HANDLING 1000 NUMBERS
ofstream o7("D:\\check7.txt");
bool arr7[1000]={0};
int s_arr7[1000];
time_t t7;
srand((unsigned)time(&t7));
//cout<<"\n\n\n 1000 NUMBERS: "<<endl;
for(i=0;i<1000;++i)
{
int r7=rand()%1000;
if(!arr7[r7])
{
s_arr7[i]=r7;
o7<<r7<<endl;
//cout<<s_arr7[i]<<endl;
}
else
i--;
arr7[r7]=1;
}
o7.close();
//cout<<"\n\n\n\n\n SORTED 1000 NUMBERS (INSERTION SORT)"<<endl;
o7.open("D:\\check7.txt");
Insertion_Sort(s_arr7,1000);
for(int i=0;i<1000;i++)
{
o7<<s_arr7[i]<<endl;
//cout<<s_arr7[i]<<endl;
}
o7.close();
//cout<<"\n\n\n\n\n SORTED 1000 NUMBERS (MERGE SORT)"<<endl;
o7.open("D:\\check7.txt");
Merge_Sort(s_arr7,0,999);
for(int i=0;i<1000;i++)
{
o7<<s_arr7[i]<<endl;
//cout<<s_arr7[i]<<endl;
}
o7.close();
//QUICK
//cout<<"\n\n\n\n\n SORTED 1000 NUMBERS (QUICK SORT | MIDDLE PIVOT)"<<endl;
o7.open("D:\\check7.txt");
Quick_Sort_MiddlePivot(s_arr7,0,999);
for(int i=0;i<1000;i++)
{
o7<<s_arr7[i]<<endl;
//cout<<s_arr7[i]<<endl;
}
o7.close();
//QUICK I
//cout<<"\n\n\n\n\n SORTED 1000 NUMBERS (QUICK SORT | RANDOM PIVOT)"<<endl;
o7.open("D:\\check7.txt");
Quick_Sort_RandomPivot(s_arr7,0,999);
for(int i=0;i<1000;i++)
{
o7<<s_arr7[i]<<endl;
//cout<<s_arr7[i]<<endl;
}
o7.close();
//QUICK II
//cout<<"\n\n\n\n\n SORTED 1000 NUMBERS (QUICK SORT | MEDIAN PIVOT)"<<endl;
o7.open("D:\\check7.txt");
Quick_Sort_MedianPivot(s_arr7,0,1000);
for(int i=0;i<1000;i++)
{
o7<<s_arr7[i]<<endl;
//cout<<s_arr7[i]<<endl;
}
o7.close();
// (QUICK III)
//cout<<"\n\n\n\n\n SORTED 1000 NUMBERS (QUICK SORT | UPDATED MEDIAN PIVOT)"<<endl;
o7.open("D:\\check7.txt");
Quick_Sort_UpdatedMedianPivot(s_arr7,0,1000);
for(int i=0;i<1000;i++)
{
o7<<s_arr7[i]<<endl;
//cout<<s_arr7[i]<<endl;
}
o7.close();
}