   Sorted insert
  I have an empty array of integers, and I want to do a sorted insert of several integers into it, but I try it but I don''t get a sorted list of integers, how is the algorithm to do it ? 
  This has just been my experience, but sorted inserts are much easier with linked lists. I am sure someone will go on about using STL vector but what good is that if you don''t understand about it yourself? Using arrays requires you to create a new array or a temporary array and copy all the values from the old array up to the insert point in the new array, then insert the value, then copy the rest of the values into the new array shifted up one place. Then, delete the old array and replace it with the new array. Needless to say, linked lists are much less work, however they do take up more memory.  ;  I have tried this:example: v[10] emptyinsert in this order: 3,4,1,6,2,0,5expected result & trace: 0,1,2,3,4,5,633,41,3,41,3,4,61,2,3,4,60,1,2,3,4,60,1,2,3,4,5,6 function insert(x)   for vector_first_pos to vector_index begin  if x > v[current_index] thenfor vector_index downto current_index begin    v[current_index+1] = v[current_index]endv[current_index] = x  elsev[vector_index] = x  end   endendthe result I get is and almost-sorted vector when I insert numbers > 0, and a almost every elements == 0 when I insert one zero. ;  First problem: "x > v[current_index]" is wrong. It should be "x < v[current_index]".Second problem: you must abort the loop as soon as x has been inserted, or structure the code differently so that x is inserted only once. ;  here is a selection sort algorithmbiggest = element[0]while (index (less than) maxarraysize){  for (index2=index+1; index2  {   if (element[index2](greater than or)=biggest)    {//swap   element[index]=element[index2];   element[index2]=biggest;   biggest = element[index];    }   }   index++;}   [edited by - GoofProg on August 4, 2003 1:20:12 AM] [edited by - GoofProg on August 4, 2003 1:21:11 AM]