I need help writing the code for this. I was thinking along the lines on how a binary search works, but instead of looking for a value you look for a location and insert the integer there and maintain the sorted order.
This is my algorithm:
Description: inserts x into the list and maintains the order
Example:
{}, {50}, {25,50}, {25,36,50}, {25,36,50,76},
{25,36,50,76}
Algorithm0:
lower = 0
upper = n
loop while lower < upper
mid = (upper+lower)/2
if x >= a[mid] then lower = mid+1, loop
if x < a[mid] then upper = mid-1, loop
//if x = a[mid] then search to right until different value found
start at mid
if x<a[mid] then mid is the place
if x>a[mid] then while (x >a[mid))
mid++
mid is the point
--------------------------------
bool COOL::insertBinary(
This is my algorithm:
Description: inserts x into the list and maintains the order
Example:
{}, {50}, {25,50}, {25,36,50}, {25,36,50,76},
{25,36,50,76}
Algorithm0:
lower = 0
upper = n
loop while lower < upper
mid = (upper+lower)/2
if x >= a[mid] then lower = mid+1, loop
if x < a[mid] then upper = mid-1, loop
//if x = a[mid] then search to right until different value found
start at mid
if x<a[mid] then mid is the place
if x>a[mid] then while (x >a[mid))
mid++
mid is the point
--------------------------------
bool COOL::insertBinary(