Implement quick sort algorithm with faulty results. Details of what I want to do can be found at the video:  Does break command take me out of inner loop or both loops? Below you'll find the code, any help will be welcome.  int main (void) {  // Array of integers to be sorted int list[] = { 3, 9, 8, 5, 7, 6, 4, 2, 1}; int arrayIndexLimit = (sizeof (list) / sizeof (int)) - 1; int temp = 0;  // "J" separates sorted part of array from unsorted one  for (int j = 0; j &lt; arrayIndexLimit; j++) {      // Find smallest value in unsorted part of array     for (int i = j; i &lt;= arrayIndexLimit; i++)     {          // Put smallest value in jth position          if (list[i] &lt; list[arrayIndexLimit])         {             temp = list[j];             list[j] = list[i];             list[i] = temp;             break;         }            // Pivot (last item of array) is the smallest         if (i == arrayIndexLimit)         {             temp = list[i];             list[i] = list[j];             list[j] = temp;             break;         }     }  // Print sorted list }
39193
In a C# (feel free to answer for other languages) loop, what's the difference between break and continue as a means to leave the structure of the loop, and go to the next iteration?  Example:  foreach (DataRow row in myTable.Rows) {     if (someConditionEvalsToTrue)     {         break; //what's the difference between this and continue ?         //continue;     } }
52342
I need to randomly 'sort' a list of integers (0-1999) in the most efficient way possible.  Any ideas?  Currently, I am doing something like this:  bool[] bIndexSet = new bool[iItemCount];  for (int iCurIndex = 0; iCurIndex &lt; iItemCount; iCurIndex++) {     int iSwapIndex = random.Next(iItemCount);     if (!bIndexSet[iSwapIndex] &amp;&amp; iSwapIndex != iCurIndex)     {         int iTemp = values[iSwapIndex];         values[iSwapIndex] = values[iCurIndex];         values[iCurIndex] = values[iSwapIndex];         bIndexSet[iCurIndex] = true;         bIndexSet[iSwapIndex] = true;     } }
56158
If I have a sorted list (say quicksort to sort), if I have a lot of values to add, is it better to suspend sorting, and add them to the end, then sort, or use binary chop to place the items correctly while adding them. Does it make a difference if the items are random, or already more or less in order?
21175
Is there a way to determine if the loop is iterating for the last time. My code looks something like this:  int[] array = {1, 2, 3...}; StringBuilder builder = new StringBuilder();  for(int i : array) {     builder.append("" + i);     if(!lastiteration)         builder.append(","); }   Now the thing is I don't want to append the comma in the last iteration. Now is there a way to determine if it is the last iteration or am I stuck with the for loop or using an external counter to keep track.
3046
Assuming I have an ArrayList  ArrayList&lt;MyClass&gt; myList;   And I want to call toArray, is there a performance reason to use  MyClass[] arr = myList.toArray(new MyClass[myList.size()]);   over  MyClass[] arr = myList.toArray(new MyClass[0]);   ?  I prefer the second style, since it's less verbose, and I assumed that the compiler will make sure the empty array doesn't really get created, but I've been wondering if that's true.  Of course, in 99% of the cases it doesn't make a difference one way or the other, but I'd like to keep a consistent style between my normal code and my optimized inner loops...
9629
I use a lot of lists and arrays but I have yet to come across a scenario in which the array list couldn't be used just as easily as, if not easier than, the linked list.  I was hoping someone could give me some examples of when the linked list is notably better.
14101
I have a loop going, but there is the possibility for exceptions to be raised inside the loop. This of course would stop my program all together. To prevent that I catch the exceptions and handle them. But then the rest of the iteration runs even though an exception occurred. Is there a keyword to use in my except: clause to just skip the rest of the current iteration?
24218
Is this functionality going to be put into a later Java version?  Can someone explain why I can't do this, as in, the technical way Java's switch statement works?
72988
Can anyone tell me the difference between break and continue statements?
29728
In other words, can I do something like  for() {     for {        for {        }     } }   Except N times? In other words, when the method creating the loops is called, it is given some parameter N, and the method would then create N of these loops nested one in another?  Of course, the idea is that there should be an "easy" or "the usual" way of doing it. I already have an idea for a very complicated one.
90301
Formatting breaks if code follows a list:   List item List item  This is in a code block  This does not work as expected   However, it works if between the list and the code   List item List item   There is a line of normal text.  This is in a code block # This does work as expected   Edit  To make this clear: This is not about nesting code in a list but about code following a (finished) list not working as expected (by me). To put it differently: Why is a list not considered finished despite of following empty lines? What do I have to do?
74356
This is a follow-up to a Stackoverflow .  There are established algorithms (such as the ) that one should use to shuffle an array, rather than relying on "naive" ad-hoc implementations.   I am now interested in proving (or disproving) that my naive algorithm is broken (as in: does not generate all possible permutations with equal probability).  Here is the algorithm:     Loop a couple of times (length of array should do), and in every iteration, get two random array indexes and swap the two elements there.   Obviously, this needs more random numbers than KFY (twice as much), but aside from that does it work properly? And what would be the appropriate number of iterations (is "length of array" enough)?
84276
I'm looking for a simple, easy to understand algorithm to alphabetically sort an array of characters in C.
2911
I have an array of Foo objects. How do I remove the second element of the array?  I need something similar to RemoveAt() but for a regular array.
93651
I want to compare 2 arrays of objects in JavaScript code.  The objects have 8 total properties, but each object will not have a value for each, and the arrays are never going to be any larger than 8 items each, so maybe the brute force method of traversing each and then looking at the values of the 8 properties is the easiest way to do what I want to do, but before implementing, I wanted to see if anyone had a more elegant solution. Any thoughts?
92200
What's the best algorithm that takes in two positive integers $a,b$   and returns a positive integer $c$, such that all $c$'s are unique and   $(a,b)$ is distinguishable from $(b,a)$; where the best means that the   length of $c$ in terms of digits is shortest possible, on average?      This implies that we can work out $a,b$ from $c$ with the same algorithm. (reversing it)   If we have a bound $x$ such that $a,b\le x$, then $f(a,b)$ has $x^2$ unique values which means our $c$ needs to take values from $[1,x^2]$ to have the least amount of digits, which can be achieved with the following function:  $$f(a,b)=(a-1)x+b$$  If $x$ does not exist, what's the optimal algorithm then?   (To make sense which algorithm is the shortest, I was comparing the length of the $c$ with the sum of lengths of $a,b$ and calculating the average which is more precise the more values we consider.)    I had two ideas so far;   $(1)$ Factorization  Take the factors of $a$ and $b$. Now you can use the second longest sequence of $0$s as a separator between factors, and the longest sequence of $0$s as a separator between the factors of the two numbers.   Example: $f(123,1007)=(3\times41 ),( 19\times53)=30410019053$  Example: $f(30,1006)=(2\times3\times5),(2\times503)=2003005000200503$  But this can be optimized, for cases such as $f(2^{64},3^{64})$, and even then, seems like it is too much extra digits.   $(2)$ Trailing zeroes  Take $a$, reverse its digits and put a random digit in front of the first digit. That way, the result does not have trailing zeroes. Then use the longest sequence of $0$s as a separator from $b$.   Example: $f(123,456)=93210456$  Example: $f(123,10100)=932100010100$  Example: $f(420,314)=902400314$  This also has room for optimization if we look at individual cases and add more specific rules. But it feels like it won't be optimal even then.   I suppose the optimal solution would need to look at couple or more cases individually?
81019
It seems that sort behaves strangely on lines such as &gt;&gt;b    $ cat test a &gt;&gt;b b c &gt; &gt;&gt;  $ sort test &gt; &gt;&gt; a b &gt;&gt;b c   I would expect the &gt;&gt;b line to be the third line output by sort but it is the fifth. Why does it do this and is there a way to make sort give my expected output?    I'm using GNU/Linux Ubuntu 16.04.