Please What Is This Algorithm That Compares............ - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Please What Is This Algorithm That Compares............ (1409 Views)
| Please What Is This Algorithm That Compares............ by cheghoon01(op): 1:01pm On Mar 16, 2016 |
For example, if 10 assignments were added to the list, with the name 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 The iteration technique will get data in the following order: Compare: 1 and 2, 1 and 3, 1 and 4, 1 and 5, 1 and 6, 1 and 7, 1 and 8, 1 and 9, 1 and 10 Compare: 2 and 3, 2 and 4, 2 and 5, 2 and 6, 2 and 7, 2 and 8, 2 and 9, 2 and 10 Compare: 3 and 4, 3 and 5, 3 and 6, 3 and 7, 3 and 8, 3 and 9, 3 and 10 Compare: 4 and 5, 4 and 6, 4 and 7, 4 and 8, 4 and 9, 4 and 10 Compare: 5 and 6, 5 and 7, 5 and 8, 5 and 9, 5 and 10 Compare: 6 and 7, 6 and 8, 6 and 9, 6 and 10 Compare: 7 and 8, 7 and 9, 7 and 10 Compare: 8 and 9, 8 and 10 Compare: 9 and 10 |
| Re: Please What Is This Algorithm That Compares............ by tr3y(m): 4:27pm On Mar 16, 2016 |
An array and a loop is all you need. |
| Re: Please What Is This Algorithm That Compares............ by ChinenyeN(m): 4:43pm On Mar 16, 2016*. Modified: 1:29am On Mar 17, 2016 |
As tr3y aptly stated, you simply need to loop it. Assuming your data structure is an array or even array-like, the algorithm would then be as follows:
|
| Re: Please What Is This Algorithm That Compares............ by larisoft: 5:52pm On Mar 16, 2016*. Modified: 6:17pm On Mar 16, 2016 |
<pre> <code> //JAVA for(int i = 0; i < arr.length; i++){ int firstNum = arr[i]; for(int j = i+1; j < arr.length; j++){ int secondNum = arr[j]; if(secondNum==firstNum){ //do stuff } } } //PHP for($i = 0; $i < count($arr); $i++){ $firstNum == $arr[$i]; for($j = $i+1; $j < count($arr); $j++){ $secondNum = $arr[$j]; if($secondNum == $firstNum){ //do stuff } } } //C# for(int i = 0; i < arr.Length; i++){ for(int j = i+1 ; j < arr.Length; j++){ if(arr[i] == arr[j]){ //do stuff } } } //Javascript for(var i = 0; i < arr.length; i++){ for(var j = i+1; j < arr.length; j++){ if(arr[i]===arr[j]){ //do stuff } } } </code> </pre> Hopefully, you speak one of these langauges. All you need do now is copy and paste. |
| Re: Please What Is This Algorithm That Compares............ by larisoft: 5:54pm On Mar 16, 2016*. Modified: 6:15pm On Mar 16, 2016 |
| Re: Please What Is This Algorithm That Compares............ by bot0k: 11:55pm On Mar 18, 2016 |
cheghoon01:A[] = {1,2,3......10}; for (i=1 to 10; i++) { for (j = i to 10; j++) { compare(A[i] and A[j]); } } ![]() |
7 Important Google Algorithm That Affect Your Website Or Blog SEO In (2018) • Simple Algorithm Exercise • Pls Programmers Help With Similarities Of Pseudocode & Algorithm • 2 • 3 • 4
How To Fix Dot Net Framework Installation On Windows 7 Ultimate • SAVE COST ON DATA BUNDLES, Get 1gb-#600 @ www.cheapmobilesubscription.com • Java Programmer Wanted
