|
001 packagepackage is used to name the directory or folder a class is in intro;
002
003 importimport means to make the classes and/or packages available in this program wiki.Wiki;
004
005 /**
006 * All about my application.
007 * @authorthis is the Javadoc tag for documenting who created the source code My Name Here
008 */
009 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects SortingAlgorithms
010 {open braces start code blocks and must be matched with a close brace
011 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer getMaxIndex(intint is the type for whole numbers and it is short for integer[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays nums, intint is the type for whole numbers and it is short for integer endIndex)
012 {open braces start code blocks and must be matched with a close brace
013 intint is the type for whole numbers and it is short for integer max=this assignment operator makes the left side equal to the right sidenums[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
014 intint is the type for whole numbers and it is short for integer pos=this assignment operator makes the left side equal to the right side0;
015 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side1; i<=this evaluates to true if the left side is not more than the right sideendIndex; i++this is the increment operator, which increases the variable by 1)
016 {open braces start code blocks and must be matched with a close brace
017 ifif executes the next statement only if the condition in parenthesis evaluates to true(nums[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays>max)
018 {open braces start code blocks and must be matched with a close brace
019 max=this assignment operator makes the left side equal to the right sidenums[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
020 pos=this assignment operator makes the left side equal to the right sidei;
021 }close braces end code blocks and must match an earlier open brace
022 }close braces end code blocks and must match an earlier open brace
023 returnreturn means to provide the result of the method and/or cease execution of the method immediately pos;
024 }close braces end code blocks and must match an earlier open brace
025
026 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value swap(intint is the type for whole numbers and it is short for integer[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays nums, intint is the type for whole numbers and it is short for integer indexA, intint is the type for whole numbers and it is short for integer indexB)
027 {open braces start code blocks and must be matched with a close brace
028 intint is the type for whole numbers and it is short for integer aux=this assignment operator makes the left side equal to the right sidenums[brackets are typically used to declare, initialize and index (indicate which element of) arraysindexA]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
029 nums[brackets are typically used to declare, initialize and index (indicate which element of) arraysindexA]brackets are typically used to declare, initialize and index (indicate which element of) arrays=this assignment operator makes the left side equal to the right sidenums[brackets are typically used to declare, initialize and index (indicate which element of) arraysindexB]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
030 nums[brackets are typically used to declare, initialize and index (indicate which element of) arraysindexB]brackets are typically used to declare, initialize and index (indicate which element of) arrays=this assignment operator makes the left side equal to the right sideaux;
031 }close braces end code blocks and must match an earlier open brace
032
033 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value insertionSort(intint is the type for whole numbers and it is short for integer[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays nums)
034 {open braces start code blocks and must be matched with a close brace
035 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side1; i<nums.length; i++this is the increment operator, which increases the variable by 1)
036 {open braces start code blocks and must be matched with a close brace
037 intint is the type for whole numbers and it is short for integer insertAt=this assignment operator makes the left side equal to the right sidei;
038 intint is the type for whole numbers and it is short for integer original=this assignment operator makes the left side equal to the right sidenums[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
039 //find where to insert
040 whilewhile is a looping structure for executing code repeatedly(insertAt>0 &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) nums[brackets are typically used to declare, initialize and index (indicate which element of) arraysinsertAt-1]brackets are typically used to declare, initialize and index (indicate which element of) arrays>nums[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays)
041 {open braces start code blocks and must be matched with a close brace
042 insertAt--this is the decrement operator, which decreases the variable by 1;
043 }close braces end code blocks and must match an earlier open brace
044 //shift values over
045 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer j=this assignment operator makes the left side equal to the right sidei; j>insertAt; j--this is the decrement operator, which decreases the variable by 1)
046 {open braces start code blocks and must be matched with a close brace
047 nums[brackets are typically used to declare, initialize and index (indicate which element of) arraysj]brackets are typically used to declare, initialize and index (indicate which element of) arrays=this assignment operator makes the left side equal to the right sidenums[brackets are typically used to declare, initialize and index (indicate which element of) arraysj-1]brackets are typically used to declare, initialize and index (indicate which element of) arrays;
048 }close braces end code blocks and must match an earlier open brace
049 //insert element at correct location
050 nums[brackets are typically used to declare, initialize and index (indicate which element of) arraysinsertAt]brackets are typically used to declare, initialize and index (indicate which element of) arrays=this assignment operator makes the left side equal to the right sideoriginal;
051 printNumbers(nums);
052 }close braces end code blocks and must match an earlier open brace
053 }close braces end code blocks and must match an earlier open brace
054
055 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value selectionSort(intint is the type for whole numbers and it is short for integer[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays nums)
056 {open braces start code blocks and must be matched with a close brace
057 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right sidenums.length-1; i>0; i--this is the decrement operator, which decreases the variable by 1)
058 {open braces start code blocks and must be matched with a close brace
059 intint is the type for whole numbers and it is short for integer maxPos=this assignment operator makes the left side equal to the right sidegetMaxIndex(nums, i);
060 swap(nums, maxPos, i);
061 printNumbers(nums);
062 }close braces end code blocks and must match an earlier open brace
063 }close braces end code blocks and must match an earlier open brace
064
065 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value printNumbers(intint is the type for whole numbers and it is short for integer[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays nums)
066 {open braces start code blocks and must be matched with a close brace
067 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<nums.length; i++this is the increment operator, which increases the variable by 1)
068 Wiki.out.print(nums[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays+adds two numbers together or concatenates Strings together" ");
069 Wiki.out.println();
070 }close braces end code blocks and must match an earlier open brace
071
072 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) voidvoid means the method does not return a value mainThe main method is the place where applications begin executing.(String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays args)
073 {open braces start code blocks and must be matched with a close brace
074 SortingAlgorithms sorter=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor SortingAlgorithms();
075
076 intint is the type for whole numbers and it is short for integer[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays nums=this assignment operator makes the left side equal to the right side{open braces start code blocks and must be matched with a close brace4, 3, 6, 2, 8, 9, 1, 5, 7}close braces end code blocks and must match an earlier open brace;
077 //print unsorted numbers
078 Wiki.out.println("Unsorted numbers: ");
079 sorter.printNumbers(nums);
080
081 Wiki.out.println("Insertion Sorting...");
082 sorter.insertionSort(nums);
083 Wiki.out.println("Sorted...");
084
085 //print sorted numbers
086 sorter.printNumbers(nums);
087
088 Wiki.out.println("Unsorted numbers: ");
089 intint is the type for whole numbers and it is short for integer[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays nums2=this assignment operator makes the left side equal to the right side{open braces start code blocks and must be matched with a close brace4, 3, 6, 2, 8, 9, 1, 5, 7}close braces end code blocks and must match an earlier open brace;
090 //print unsorted numbers
091 sorter.printNumbers(nums2);
092
093 Wiki.out.println("Selection Sorting...");
094 sorter.selectionSort(nums2);
095 Wiki.out.println("Sorted...");
096
097 //print sorted numbers
098 sorter.printNumbers(nums2);
099
100 }close braces end code blocks and must match an earlier open brace
101 }close braces end code blocks and must match an earlier open brace
|