-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMergeSort.py
35 lines (32 loc) · 6.63 KB
/
MergeSort.py
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
list1 = [6347, 7831, 3022, 6411, 2708, 2424, 9791, 6601, 6014, 437, 1152, 4306, 8596, 3981, 8425, 5320, 4410, 7533, 6421, 7746, 8183, 7293, 1871, 1384, 5884, 5832, 8457, 3756, 2358, 6506, 4978, 2950, 8162, 1600, 7085, 2409, 3908, 8201, 782, 9638, 2615, 8524, 6074, 1164, 1510, 6892, 7444, 1786, 9587, 8581, 7271, 1493, 5413, 9783, 8986, 5012, 3502, 932, 3769, 4477, 3316, 8847, 7736, 3084, 6155, 8931, 9476, 8685, 3262, 1452, 5835, 2694, 2778, 41, 3470, 1053, 7664, 8851, 6785, 7764, 8173, 2432, 1838, 7787, 3444, 9026, 55, 3672, 5122, 425, 1148, 3911, 2507, 9410, 7403, 5948, 8027, 9386, 3689, 6806, 5319, 6813, 4373, 4542, 404, 4969, 2621, 2141, 887, 765, 9930, 86, 588, 243, 6160, 1082, 3303, 5268, 5206, 7070, 6255, 3638, 5430, 8952, 285, 8559, 4929, 6396, 592, 9192, 2814, 1561, 9852, 9274, 8902, 7701, 149, 440, 3136, 6195, 3715, 7901, 2282, 4139, 4628, 8175, 7353, 4200, 727, 2293, 8659, 4265, 7208, 2624, 2330, 2188, 6675, 8118, 4405, 9873, 9699, 2845, 4780, 3610, 3745, 7774, 392, 1678, 2928, 1360, 2276, 7107, 7856, 1771, 8236, 7093, 3790, 7388, 2800, 4425, 4493, 207, 131, 1576, 6826, 3912, 2144, 251, 4261, 9034, 6287, 3956, 6116, 415, 2396, 3943, 6823, 877, 5904, 7183, 3134, 9096, 2415, 7174, 1118, 7499, 8992, 115, 4295, 4599, 2698, 5713, 6521, 2940, 4736, 1642, 2744, 6878, 8138, 5862, 4677, 557, 2482, 6802, 5394, 307, 1447, 2943, 5363, 4138, 1641, 6325, 3655, 2835, 8181, 4964, 8312, 3977, 4801, 93, 1973, 1999, 5152, 1295, 979, 3257, 6279, 9478, 6199, 1347, 9060, 5431, 4327, 8729, 3095, 2026, 9459, 2631, 4363, 5350, 8906, 1012, 7285, 2370, 6200, 8830, 6842, 4224, 1258, 9559, 9467, 8890, 1793, 6171, 7589, 5287, 3946, 716, 7258, 5707, 4878, 1144, 3170, 4658, 4136, 3067, 842, 4656, 5356, 4185, 3662, 1536, 3560, 3686, 1394, 2465, 8122, 6911, 3487, 8194, 2596, 6752, 5744, 6520, 8857, 6180, 6020, 9561, 8600, 652, 7193, 6924, 9395, 8368, 109, 5502, 8974, 3334, 7190, 4684, 6602, 1969, 9444, 3914, 3442, 3627, 9002, 3003, 1110, 5087, 6989, 7557, 1872, 1271, 8551, 3567, 5758, 3703, 7357, 684, 2812, 8558, 3945, 3167, 36, 7434, 8300, 474, 1628, 5368, 3279, 8199, 5847, 378, 2949, 5298, 1517, 8538, 4575, 1848, 9508, 9868, 467, 5242, 9224, 1249, 5412, 3147, 2443, 2677, 9097, 9079, 4429, 888, 4400, 8450, 2518, 8563, 4483, 9474, 1196, 7493, 5813, 5315, 7843, 171, 7364, 8277, 1513, 2363, 4096, 8833, 3196, 8646, 4486, 1417, 9717, 7818, 5435, 5979, 4056, 3639, 5333, 4008, 4339, 5778, 695, 8399, 5704, 4594, 1858, 647, 7441, 6689, 5135, 1106, 5918, 2770, 7871, 6480, 990, 6848, 9219, 9985, 3936, 836, 4965, 5724, 4908, 1917, 8407, 6773, 7717, 510, 6410, 5000, 9522, 4012, 8951, 1032, 7344, 547, 3117, 3739, 2382, 6999, 8773, 7179, 9176, 2580, 6293, 8567, 5204, 9748, 3858, 5658, 2149, 9679, 7735, 4050, 2000, 5732, 641, 6257, 2964, 9962, 2243, 847, 4106, 779, 1243, 6010, 4654, 9070, 9480, 193, 2740, 6971, 6134, 6555, 5398, 8687, 1856, 182, 8021, 1873, 1809, 7607, 4581, 6070, 7237, 8509, 9425, 3372, 7304, 9157, 6549, 9404, 8120, 4196, 9014, 5579, 7868, 2461, 7225, 5208, 3978, 3781, 3422, 7368, 9333, 1396, 7632, 9454, 1425, 9159, 5680, 2483, 9228, 9249, 631, 2747, 5595, 7074, 4649, 9787, 6636, 6788, 4892, 4148, 4734, 8637, 47, 6147, 3927, 6553, 2729, 8458, 8614, 9795, 4231, 9217, 1277, 112, 1623, 3307, 1532, 4240, 7865, 3576, 4819, 7324, 4509, 8763, 8544, 6113, 2028, 179, 1647, 3398, 3094, 220, 4311, 2352, 8340, 3028, 3925, 583, 1520, 7064, 7416, 2423, 6203, 8904, 3958, 1283, 5141, 7165, 9199, 1442, 2931, 5841, 2271, 4471, 6817, 3393, 726, 26, 7457, 8846, 3924, 8914, 2111, 8967, 77, 624, 253, 6937, 3491, 8083, 1327, 5561, 969, 9099, 2430, 8273, 1998, 3757, 8272, 9584, 4722, 3701, 4709, 4585, 2344, 3080, 2864, 2804, 2091, 7121, 9445, 3916, 5305, 4199, 6457, 8096, 9912, 5566, 9417, 7770, 9376, 3498, 6165, 3997, 8610, 3481, 811, 8115, 6657, 8266, 1267, 1021, 3090, 8812, 1050, 4966, 9878, 1565, 8157, 2643, 6448, 4294, 4650, 1354, 8945, 6452, 4800, 8079, 1619, 8806, 5950, 4784, 8873, 3294, 9905, 813, 427, 6622, 8817, 9062, 3904, 9080, 581, 9344, 8618, 2919, 2937, 8057, 8957, 7094, 829, 1967, 6991, 1141, 8000, 5083, 4861, 1434, 5635, 6992, 217, 4061, 9485, 5689, 1204, 219, 4215, 860, 4897, 2816, 9527, 6237, 8257, 4201, 7185, 9536, 5839, 7394, 3390, 1366, 1489, 8710, 3096, 8064, 9909, 7233, 5392, 6049, 4062, 7855, 335, 8073, 1760, 5480, 4156, 6528, 9593, 6739, 261, 2838, 3106, 3533, 891, 157, 1370, 3152, 1129, 199, 3823, 9200, 4517, 2165, 5447, 7585, 7010, 4312, 3388, 3961, 7668, 890, 3370, 6253, 9952, 6017, 634, 6305, 7135, 2367, 6071, 6726, 5330, 3953, 3919, 9705, 9809, 3750, 8800, 9637, 6775, 6833, 9585, 9718, 138, 2020, 6607, 3582, 2532, 4794, 3366, 5700, 9316, 7041, 5819, 7812, 3515, 9966, 8270, 796, 6156, 137, 3431, 6152, 339, 9233, 3198, 6641, 3499, 7625, 6130, 4836, 7342, 7988, 8838, 5247, 2472, 1223, 5654, 3440, 2160, 462, 6345, 8527, 5860, 6111, 1068, 3465, 49, 2558, 8219, 8804, 8844, 7192, 9656, 5814, 2076, 5935, 8537, 6652, 5057, 1720, 9501, 5490, 5552, 6759, 3418, 9288, 8143, 2825, 1124, 507, 8200, 9483, 1435, 9553, 2854, 134, 3199, 4690, 6952, 686, 896, 2510, 4171, 2057, 6158, 4973, 2003, 9450, 1880, 1229, 3252, 2476, 9745, 382, 4173, 4943, 4674, 5288, 6239, 6625, 4985, 5629, 3677, 4639, 826, 84, 8869, 889, 5377, 5184, 707, 5945, 5596, 6119, 5538, 401, 4622, 1601, 7250, 7594, 2877, 8097, 6745, 3571, 7235, 9337, 2201, 4664, 4502, 1891, 5685, 2661, 3923, 4708, 6101, 3704, 1469, 7373, 5023, 3089, 2320, 8196, 9518, 6175, 1738, 1319, 8751, 461, 1248, 883, 4074, 5794, 3016, 5257, 2407, 6416, 7021, 5237, 2335, 4291, 5116, 1008, 5973, 3547, 314, 1465, 7543, 2613, 2033, 7613, 4243, 2823, 7331, 9086, 8473, 177, 7186, 7879, 5049, 6770, 7798, 8054, 8582, 5539, 6756, 9437, 5792, 4046, 3415, 2637, 2458, 3160, 1629, 921, 1808, 5108, 1115, 628, 2270, 4377, 7370, 2475, 2539, 3860, 6703, 1109, 5796, 5690, 8850, 7078, 1509, 9065, 2392, 8624, 854, 9686, 8959, 1803, 7234, 6791, 2827, 7467, 6958, 9413, 9181, 2124, 6569, 7890, 491, 8094]
def mergesort(list):
last = len(list)
mid = int(last/2)
if last > 1:
return(merge(mergesort(list[:mid]),mergesort(list[mid:])))
else:
return(merge(list[:mid], list[mid:]))
def merge(list1, list2):
#print(list1)
#print(list2)
mergedlist = []
while list1 != [] or list2 !=[]:
if list1 == []:
mergedlist.append(list2[0])
list2.pop(0)
print(mergedlist)
elif list2 == []:
mergedlist.append(list1[0])
list1.pop(0)
print(mergedlist)
elif list1[0] <= list2[0]:
mergedlist.append(list1[0])
list1.pop(0)
print(mergedlist)
elif list2[0] < list1[0]:
mergedlist.append(list2[0])
list2.pop(0)
print(mergedlist)
return(mergedlist)
print(mergedlist)
print(mergesort(list1))