473,803 Members | 3,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dropping lowest value after an ascending sort

sonic
40 New Member
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
  1.  
  2.  
  3. void sort(double* score, int size)
  4. {
  5.     int startScan;
  6.     int minIndex;
  7.     double minValue;
  8.  
  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. }
  25.  
  26.  
Feb 6 '07 #1
2 2022
horace1
1,510 Recognized Expert Top Contributor
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;
  4.  
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
Ganon11
3,652 Recognized Expert Specialist
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

1
1779
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++)
3
2745
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 reports at the plan (overall totals), department and division levels which have sorting and grouping implemented with this new
1
5758
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 sorts ascending and second sorts decending etc. Can anyone point me in a direction? Thanks, Mark
17
7722
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
7
9897
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 attack something like this? Any help is greatly appreciated. thanks!
11
18333
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 can be sorted ascending and others descending? Easy enough if the sort values are numeric (just negate the value), but what about text? Is the only option to define an external sorting function to loop through the list and perform the...
6
3716
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 num; clrscr(); cout<<"ENTER NUMBERS TO SORT THEM IN ASCENDING ORDER & FIND THE AVERAGE"<<endl; for(int times=0;times<=10;times++)
4
2928
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 iterators to first and last element of the map. My question is: Does begin() and rbegin() guarantee that returned iterators point on the pair with lowest and gratest value?
30
5259
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. I am new to Programming and C#. Thanks for any help you can provide Thomas
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.