Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

quick + merge sort + 2048 numeros aleatorios

  • Loading branch information...
commit 899e351ccbbfd77a244eda67706af232d358d8da 1 parent 9b4e136
@3kthor3adward authored
View
2  Enteros.txt
@@ -1 +1 @@
-3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 3 6 2 8 5 3 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99 677 184 378 1063 562 1234 729 1168 214 1004 620 1918 847 676 941 1981 382 935 1633 567 411 583 1221 134 1604 540 551 615 773 1171 1708 1561 805 174 207 1578 946 1694 908 594 520 1858 425 2 475 92 118 1817 1819 1410 766 1573 751 1418 1347 255 932 1998 665 1465 866 1932 1954 117 350 1786 1075 67 563 1678 587 777 375 1595 1816 302 1022 1145 421 185 1158 1106 618 1149 159 568 603 365 2035 1634 1025 1026 2025 1288 1284 306 414 1281 1956 1526 1778 767 1134 1055 752 1865 1920 947 189 385 1828 2018 610 906 1414 1240 8 496 13 1897 136 669 1856 928 1614 1511 1003 1326 1173 1792 1756 167 624 1603 1343 146 1157 1341 196 1089 812 1831 990 703 1676 1056 1491 1855 4 985 976 1140 1807 735 231 176 138 1623 147 1271 1788 927 330 160 749 585 939 68 193 245 1010 1490 738 300 1495 1966 959 1806 213 922 1609 919 1077 807 950 497 268 1408 570 1501 1074 197 1263 929 1970 888 516 992 1316 63 1052 1097 1804 229 1510 905 1744 240 898 1333 1277 1013 532 658 861 1610 1761 450 1017 1665 1940 434 1094 712 1470 1249 1466 1021 1296 1735 1768 1407 1295 1750 1933 1836 1481 297 1770 1059 530 1606 1102 1568 383 1906 1692 394 1415 899 1745 1890 1500 143 294 781 1143 1238 261 1471 1 1085 135 800 335 1518 1739 1048 1111 827 388 168 619 1222 463 62 539 1345 1798 311 1891 1405 1072 1314 205 1589 498 595 628 12 533 761 312 1852 286 2034 366 670 14 1724 1741 1899 1554 371 1793 45 784 1244 95 1122 1799 1053 1963 6 1889 420 234 1142 50 1242 580 1801 251 162 409 332 1895 1464 1620 1519 395 1404 697 258 1201 58 705 293 1371 386 344 354 323 1432 1648 1760 114 1302 314 850 675 913 275 1536 1496 1268 2037 1070 1613 1126 589 1225 986 52 814 65 470 838 1279 281 543 1580 844 415 1406 28 1476 1315 1419 1040 104 1757 667 1065 218 984 631 756 934 1245 1474 449 1509 1869 640 1849 1413 1334 659 466 2011 1154 393 536 397 1593 1297 796 56 1841 865 1877 1846 1379 1924 441 1638 626 2017 474 1996 458 137 1286 1427 1005 1901 462 452 19 1280 1450 384 719 348 1629 1664 128 460 739 304 1748 1009 1818 1183 889 1181 448 1994 1216 1785 1823 1912 867 1202 1346 1721 694 872 1092 447 970 1386 1451 1170 890 183 106 1308 1591 1514 82 254 392 284 1844 1349 101 1800 1141 145 614 224 1964 44 144 1524 1103 1088 1810 203 1321 1989 737 997 1969 894 799 837 1914 1340 1381 2036 859 412 895 1863 636 1137 791 912 1306 1499 999 1632 622 1837 883 1702 246 1455 1186 969 1938 685 1669 1548 1054 1974 680 1218 1562 1483 2031 171 1118 642 651 707 1704 1544 1283 1312 1995 579 468 2007 690 1184 276 405 1504 1213 660 49 1488 208 1736 633 1019 528 112 2046 37 998 60 1882 975 801 1947 1624 225 2005 410 1946 1071 1625 825 1311 1164 545 782 1755 1423 2038 432 443 549 478 875 505 2033 358 1777 686 127 515 1461 983 834 1671 673 1204 1911 1861 1180 1752 1452 230 769 1550 1960 728 479 303 742 1695 31 1356 361 674 874 851 994 1394 711 1559 1472 142 566 1586 938 691 1392 1968 1913 435 320 1522 1469 863 732 900 1096 1233 1095 701 1791 88 292 897 730 1275 644 1803 569 2008 1892 477 1839 1332 1480 1246 1272 1552 980 1289 233 1628 1547 1886 1324 1663 1380 1456 1336 2021 830 1539 57 1717 1926 103 2030 1100 1391 1515 1125 1549 433 219 1080 1325 1540 1159 967 810 1790 547 743 1599 924 1487 152 1493 1670 809 1304 1742 317 210 786 1424 1212 1898 1437 1583 518 1528 1545 309 403 2015 398 1079 657 296 1185 1779 920 1229 132 1082 1636 1165 2022 1378 1108 554 1626 613 1163 1683 1458 600 1903 1227 1322 1506 1331 1273 725 1611 1508 1962 1820 634 958 2039 21 1113 249 1879 1815 683 1337 1189 363 744 655 1350 753 1513 1615 1725 1370 1290 1530 1138 244 34 307 1902 1012 345 747 471 574 256 509 971 1399 1139 1044 123 507 265 288 616 1498 637 1525 278 1600 954 2028 1193 164 1658 833 871 419 831 772 96 1941 1675 301 223 413 662 387 216 582 1250 1028 186 1257 1716 39 188 1893 487 573 116 1543 1428 1971 822 1885 1278 745 1162 1179 836 1090 1915 1916 933 201 1563 726 84 768 1256 1596 399 1672 1980 1975 696 1796 1987 672 485 910 70 1769 968 163 722 1046 1358 30 802 111 1209 69 1241 480 1114 119 1908 1585 360 1460 461 1032 942 1690 553 1007 1463 841 1373 564 961 191 1875 1057 1220 689 1953 1409 649 1348 1045 1976 629 173 923 1196 351 250 262 1148 819 113 280 178 431 1376 1949 750 1482 951 1662 1887 699 346 2019 404 1840 700 1617 1700 1783 427 1710 937 1719 226 180 488 1188 1862 965 367 977 1169 198 190 695 1396 522 390 1952 1123 1267 1942 1616 1986 1105 1627 952 15 1843 525 1224 1520 793 1834 1389 882 1156 1387 1805 369 870 42 1239 270 1116 597 1857 252 1251 141 1384 2012 1426 734 661 376 763 1453 1647 1605 527 1300 1622 23 1309 1795 1959 1479 1436 1274 151 1684 891 1929 1661 1883 2026 436 1822 577 2013 1753 1674 71 107 1923 1342 740 1523 1645 723 1351 1254 1531 1835 291 925 1601 195 51 944 641 1826 1353 325 1781 1385 102 1442 1853 1537 1327 1997 1135 988 73 886 1230 1049 1366 1310 87 1172 1618 1223 499 1214 1128 357 108 1868 1874 1150 1018 396 1767 379 1577 560 963 77 417 467 154 832 884 1754 1136 343 821 2040 64 1117 599 353 1789 591 20 1894 1104 602 671 524 1002 273 1086 1992 161 269 1001 1446 1706 1194 2016 1812 664 843 2045 283 260 702 576 43 1666 1176 10 684 759 172 806 1051 347 1649 623 1253 630 511 61 1190 1582 40 538 1630 816 2010 780 1979 1766 948 2020 1517 588 1850 1612 1904 1237 512 1765 513 83 681 653 1619 794 1502 1397 232 508 1252 1848 1243 1365 1130 1579 1784 911 835 247 1198 1931 1248 1631 316 1425 372 787 2042 121 1034 1109 1152 1727 1362 1787 868 1211 1689 1174 227 298 295 277 748 558 803 305 760 175 1369 1650 1236 1743 1301 333 1569 221 453 846 1925 1876 1697 1646 559 1497 1084 1930 215 1203 878 72 1870 698 1039 1035 1064 721 1266 491 565 1440 535 1270 16 517 845 1485 1110 1977 1955 1015 86 1468 552 78 1680 122 1132 1749 625 643 328 1507 1685 692 1534 1851 1557 1881 778 1965 572 257 608 1430 401 1884 1036 1532 993 854 1759 29 1226 811 1083 896 604 1560 1654 211 483 1178 1091 285 1978 617 1120 1285 1712 446 1682 1775 11 1827 1691 59 1433 85 1037 342 1031 26 1068 754 32 1762 1124 1608 1688 880 1255 1737 1738 79 656 1208 1656 1076 1023 1421 901 654 571 1572 148 1024 267 1192 1317 17 797 428 720 373 7 1722 779 481 1829 1282 1637 650 1305 1667 1429 1008 1794 541 523 1993 1147 120 808 1825 930 1813 1129 741 239 581 795 1073 2000 1983 1651 418 792 1177 1944 337 892 362 1200 652 1782 266 578 1709 758 156 974 408 2009 1565 820 1287 1847 364 1363 1014 957 9 693 1042 1909 647 612 514 1734 713 715 2032 1205 972 209 1403 1824 289 1199 1444 1144 2044 339 718 1945 1388 1030 907 1330 444 439 2048 881 1344 437 1740 170 966 1489 1541 586 679 338 1598 1711 179 1434 765 771 1187 89 1607 274 1155 546 1814 584 459 607 194 842 936 1462 381 1486 1146 606 340 1950 1431 1907 1265 1575 996 1016 1990 609 33 1101 94 1264 1276 544 590 877 2006 955 192 66 893 964 2047 1888 956 1043 1584 1957 374 430 921 648 646 263 1232 1687 1746 217 356 916 237 1982 334 2004 166 561 46 1029 1713 1131 38 91 1653 1838 914 1050 550 1643 1878 1099 1715 1258 706 1219 621 5 1020 1590 456 1067 1335 1355 904 1473 368 1475 389 1259 635 455 402 1443 75 979 1402 149 500 856 785 25 1597 1166 1927 1842 1922 264 1866 1707 494 1390 1292 1564 501 1668 1574 1121 873 290 909 1730 105 327 1081 1571 666 248 1714 124 55 1910 1718 272 917 1041 788 181 442 238 1705 926 724 1686 341 1535 1115 627 605 1641 596 1058 918 548 817 824 519 1457 429 1729 1112 813 133 1066 858 2001 445 182 157 1119 1078 2014 1153 236 1581 1679 943 1935 733 391 426 1991 1984 1352 80 1217 1512 534 1262 931 76 1364 682 2043 1797 490 1368 129 502 41 1210 202 1728 1393 542 495 1060 484 1832 454 1038 1151 1566 1533 1652 1640 1127 1867 798 823 1934 1973 1693 1228 1558 1484 775 717 158 48 879 557 1556 1206 1175 318 852 422 1454 1551 1062 783 982 1576 506 1338 1133 638 860 714 529 206 457 1958 100 639 1821 1763 489 503 406 1771 336 1411 1093 109 1733 1006 1191 903 1639 243 1298 704 493 424 1449 2041 826 953 1260 1802 829 1774 1936 1098 1542 709 287 828 1900 1323 1294 2029 1503 1339 187 1299 1860 1235 1811 510 1859 789 200 1873 1673 1917 736 1383 27 115 235 521 989 177 1313 308 945 1398 1527 940 1864 537 1635 645 1000 708 1723 1939 204 1570 1377 329 1269 1833 1329 710 131 1261 380 1361 1567 1422 632 864 1047 668 1905 2024 1872 2023 1985 315 1160 1587 1374 611 155 259 949 1726 556 54 663 1660 22 885 1594 492 139 1478 451 1731 1830 299 1896 862 1751 400 555 1928 1291 593 1207 1247 1948 220 757 1161 465 1069 1477 1412 770 1943 199 282 473 592 849 24 764 279 271 1720 804 678 1439 1401 222 731 1871 1764 1492 242 1027 1354 973 575 815 98 2003 1447 165 1182 915 1521 960 1546 130 2027 464 1357 869 746 687 1416 407 995 818 370 1445 228 1747 2002 322 1033 1303 1773 1951 1293 1588 1602 1677 212 1448 35 1732 1435 1375 1772 1553 1880 110 1372 1505 1307 1320 126 349 1961 1328 169 53 472 438 1699 469 876 1776 1441 153 241 423 321 762 1919 1438 504 1701 716 1107 857 601 1642 991 90 1988 355 359 1621 1644 36 1516 1318 1319 1592 1555 839 531 978 1359 962 1758 476 727 1655 1657 1231 774 331 902 313 1011 1937 319 352 1459 887 482 981 125 81 1972 1420 1061 324 1195 97 326 790 310 1215 1494 74 1681 1467 18 140 1382 1360 1698 1780 848 1999 416 150 1845 47 1854 1395 1921 1087 486 1703 1809 1696 855 1400 440 3 93 526 1167 253 1417 1808 1197 776 1659 1367
View
46 src/Main.java
@@ -15,6 +15,7 @@
*/
public class Main {
+ private static Comparable[] _data;
private static String _uso = "\nUso: java Main - [i|d] archivo.txt";
private static int _nTests = 500;
private static MethodTester _methodTesters[] = //<editor-fold defaultstate="collapsed" desc="wrappers">
@@ -23,6 +24,30 @@
@Override
public Comparable[] testMethod(Comparable[] elements) {
+ return Ordena.quickSort(elements);
+ }
+
+ @Override
+ public String getMethodName() {
+ return "quickSort";
+ }
+ },
+ new MethodTester() {
+
+ @Override
+ public Comparable[] testMethod(Comparable[] elements) {
+ return Ordena.mergeSort(elements);
+ }
+
+ @Override
+ public String getMethodName() {
+ return "mergeSort";
+ }
+ },
+ new MethodTester() {
+
+ @Override
+ public Comparable[] testMethod(Comparable[] elements) {
return Ordena.bubbleSort(elements);
}
@@ -47,24 +72,26 @@ public String getMethodName() {
@Override
public Comparable[] testMethod(Comparable[] elements) {
- return Ordena.quickSort(elements);
+ Ordena.quickSortInPlace(elements);
+ return null;
}
@Override
public String getMethodName() {
- return "quickSort";
+ return "quickSortInPlace";
}
},
new MethodTester() {
@Override
public Comparable[] testMethod(Comparable[] elements) {
- return Ordena.mergeSort(elements);
+ Ordena.mergeInPlaceSort(elements);
+ return null;
}
@Override
public String getMethodName() {
- return "mergeSort";
+ return "mergeInPlaceSort";
}
}
};
@@ -92,7 +119,7 @@ private static BigDecimal testTimeInSeconds(int times, MethodTester tester, fina
public String getMethodName();
}
- private static Comparable[] readData(String[] args) throws FileNotFoundException, SortException {
+ private static Comparable[] readData(final String[] args) throws FileNotFoundException, SortException {
if (args.length != 2) {
throw new SortException("Argumentos invalidos." + _uso);
}
@@ -121,18 +148,19 @@ private static BigDecimal testTimeInSeconds(int times, MethodTester tester, fina
return results;
}
- private static void execute(Comparable[] elements) {
+ private static void execute(final Comparable[] elements) {
for (MethodTester tester : _methodTesters) {
- System.out.println(">>> " + tester.getMethodName() + ": promediando tiempo con " + _nTests + " pruebas...");
+ System.out.println(">>> " + tester.getMethodName() + ": Promediando tiempo. Ordendar " + _nTests + " veces " + _data.length + " elementos...");
BigDecimal time = testTimeInSeconds(_nTests, tester, elements);
System.out.println(">>> " + time.toEngineeringString() + " seg.");
tester.testMethod(elements);
}
}
- public static void main(String... args) {
+ public static void main(final String... args) {
try {
- execute(readData(args));
+ _data = readData(args);
+ execute(_data);
} catch (FileNotFoundException ex) {
System.out.println("archivo no encontrado");
} catch (SortException ex) {
View
103 src/mx/unam/fciencias/ordering/Ordena.java
@@ -1,6 +1,8 @@
package mx.unam.fciencias.ordering;
import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.LinkedList;
/**
*
@@ -9,40 +11,113 @@
public class Ordena {
public static boolean _silentTestFlag = false;
- public static boolean _ascendingOrder = true;
public static Comparable[] insertionSort(final Comparable[] elements) {
throw new UnsupportedOperationException("Not yet implemented");
}
+ //<editor-fold defaultstate="collapsed" desc="bubble">
public static Comparable[] bubbleSort(final Comparable[] elements) {
- Comparable[] results = (Comparable[]) elements.clone();
+ Comparable[] results = clone(elements);
for (int n = 0; n < elements.length; n++) {
for (int i = 0; i < results.length - 1; i++) {
- boolean isGreater = results[i].compareTo(results[i + 1]) > 0;
- if (isGreater && _ascendingOrder || !isGreater && !_ascendingOrder) {
+ if (results[i].compareTo(results[i + 1]) > 0) {
swap(results, i, i + 1);
}
}
}
return results;
}
+ //</editor-fold>
+ //<editor-fold defaultstate="collapsed" desc="merge">
public static Comparable[] mergeSort(final Comparable[] elements) {
- throw new UnsupportedOperationException("Not yet implemented");
+ LinkedList<Comparable> listResults = merge_Sort(new LinkedList<Comparable>(Arrays.asList(clone(elements))));
+ Comparable[] results = new Comparable[listResults.size()];
+ results = listResults.toArray(results);
+ return results;
+ }
+
+ private static LinkedList<Comparable> merge_Sort(final LinkedList<Comparable> elements) {
+ if (elements.size() <= 1) {
+ return elements;
+ }
+ int middle = elements.size() / 2;
+ LinkedList<Comparable> left = new LinkedList<Comparable>();
+ LinkedList<Comparable> right = new LinkedList<Comparable>();
+ left.addAll(elements.subList(0, middle));
+ right.addAll(elements.subList(middle, elements.size()));
+ left = merge_Sort(left);
+ right = merge_Sort(right);
+ return merge(left, right);
}
+ private static LinkedList<Comparable> merge(LinkedList<Comparable> left, LinkedList<Comparable> right) {
+ LinkedList<Comparable> results = new LinkedList< Comparable>();
+ int pos = 0;
+ while (left.size() > 0 || right.size() > 0) {
+ if (left.size() > 0 && right.size() > 0) {
+ if (left.get(0).compareTo(right.get(0)) <= 0) {
+ results.addLast(left.getFirst());
+ left.removeFirst();
+ } else {
+ results.addLast(right.getFirst());
+ right.removeFirst();
+ }
+ } else if (left.size() > 0) {
+ results.addLast(left.getFirst());
+ left.removeFirst();
+ } else if (right.size() > 0) {
+ results.addLast(right.getFirst());
+ right.removeFirst();
+ }
+ }
+ return results;
+ }
+ //</editor-fold>
+
+ //<editor-fold defaultstate="collapsed" desc="quick">
public static Comparable[] quickSort(final Comparable[] elements) {
+ Comparable[] results = clone(elements);
+ quickSort(results, 0, elements.length - 1);
+ return results;
+ }
+
+ private static void quickSort(Comparable[] list, int lowIndex, int highIndex) {
+ int lIndex = lowIndex, hIndex = highIndex;
+ Comparable center = list[(lowIndex + highIndex) / 2];
+
+ while (lIndex <= hIndex) {
+ while (list[lIndex].compareTo(center) < 0) {
+ lIndex++;
+ }
+ while (list[hIndex].compareTo(center) > 0) {
+ hIndex--;
+ }
+ if (lIndex <= hIndex) {
+ swap(list, lIndex, hIndex);
+ lIndex++;
+ hIndex--;
+ }
+ }
+
+ if (lowIndex < hIndex) {
+ quickSort(list, lowIndex, hIndex);
+ }
+ if (lIndex < highIndex) {
+ quickSort(list, lIndex, highIndex);
+ }
+ }
+ //</editor-fold>
+
+ public static void mergeInPlaceSort(Comparable[] elements) {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public static void quickSortInPlace(Comparable[] elements) {
throw new UnsupportedOperationException("Not yet implemented");
}
- /*
- * public static void mergeInPlaceSort(Comparable[] elements) { throw new
- * UnsupportedOperationException("Not yet implemented"); }
- *
- * public static void quickSortInPlace(Comparable[] elements) { throw new
- * UnsupportedOperationException("Not yet implemented"); }
- */
private static void outResult(final Comparable[] elements, OutputStream output) {
throw new UnsupportedOperationException("Not yet implemented");
}
@@ -52,4 +127,8 @@ private static void swap(Comparable[] source, int indexA, int indexB) {
source[indexA] = source[indexB];
source[indexB] = backupA;
}
+
+ private static Comparable[] clone(final Comparable[] elements) {
+ return (Comparable[]) elements.clone();
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.