472,780 Members | 1,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

dropping lowest value after an ascending sort

Does anyone know what I can do to this function to get it to drop the lowest value? Thanks for any insight.

Expand|Select|Wrap|Line Numbers
  3. void sort(double* score, int size)
  4. {
  5.     int startScan;
  6.     int minIndex;
  7.     double minValue;
  9.     for (startScan = 0; startScan < (size - 1); startScan++)
  10.     {
  11.         minIndex = startScan;
  12.         minValue = score[startScan];
  13.         for (int index = startScan + 1; index < size; index++)
  14.         {
  15.             if (score[index] < minValue)
  16.             {
  17.                 minValue = score[index];
  18.                 minIndex = index;
  19.             }
  20.         }
  21.         score[minIndex] = score[startScan];
  22.         score[startScan] = minValue;
  23.     }
  24. }
Feb 6 '07 #1
2 1974
1,510 Expert 1GB
at the end of your sort you could shuffle the elements down one to remove the minimum value, e.g.
Expand|Select|Wrap|Line Numbers
  1.     for (startScan = 0; startScan < (size - 1); startScan++)
  2.         score[startScan]=score[startScan+1];
  3.     score[size-1]=0;
you have to decide what you will put at the end to replace the last element moved, in this case I put a 0
Feb 6 '07 #2
3,652 Expert 2GB
Since you are sorting from lowest to highest, after you are finished the sort, increment the pointer by one value. This will leave the lowest value in memory (in the location just before the current pointer), but the array will now start with the second lowest value. If you want to avoid memory leak, you can define a new pointer pointing to the same value as the original pointer, increment the original pointer, and then delete the value stored in the new pointer.
Feb 6 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

by: wil smiths | last post by:
int i,j,val=4; int arr={4,7,3,9}; int temp=-1; int iptr=-1; for(i=0; i<=val-2;i++) { iptr=i; for(j=i+1;j<=val-1;j++)
by: ahaque38 | last post by:
Hello. Using A2K SP3, I am having the following problem with a report using "Sorting and Grouping". I have recently added a grouping in the reports for "Category2<>'CONTRACTS'". I have...
by: Mark | last post by:
Rather than have only one column sorted in a single direction in a listview. I would like to be able to sort on any column in alternating directions (ascending,descending) eg. First column click...
by: rhitz1218 | last post by:
Hi, I'm trying to create a function that will sort a number's digits from highest to lowest. For example 1000 - will become 0001 or 1234 to 4321
by: Paulers | last post by:
Hello I have an ArrayList full of Person objects. I would like to sort the object array by the objects property 'Name' so when I loop through it and populate a combobox they are in order. How do I...
by: dwelden | last post by:
I have successfully used the sort lambda construct described in http://mail.python.org/pipermail/python-list/2006-April/377443.html. However, how do I take it one step further such that some values...
by: reon | last post by:
Here is my source code.... And any one pls help me how can we find the output integers sort by ascending and find there average... #include<iostream.h> #include<conio.h> void main() { int...
by: tomek milewski | last post by:
Hello, I have a map with keys that can be compared each other. I need a method that returns the lowest and the greatest key from that map. Now I'm using begin() and rbegin() which gives...
by: =?Utf-8?B?VGhvbWFzVDIy?= | last post by:
Hello, I have an array that holds 4 values ( they contain random numbers). I would like to find the lowest value (if there is a tie i would like to find one of the tie.) then remove that value....
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.