Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-20-2009, 12:12 AM   PM User | #1
Nblufire12
Regular Coder

 
Join Date: Apr 2008
Posts: 257
Thanks: 15
Thanked 0 Times in 0 Posts
Nblufire12 is an unknown quantity at this point
Insertion sort C++ help

hey guys,

I need to sort an array in ascending order in C++ AS the user inputs the numbers in main,

for example, in main

Code:
for (int a=0;a<10;a++) {

		cout<<"Enter a Number: " << endl;
		cin >> numEntered;
		insertArray(array, numEntered, a);
	}
can you guys gimme some examples to sort the array AS the user inputs the number after the next number?
Nblufire12 is offline   Reply With Quote
Old 01-20-2009, 01:03 AM   PM User | #2
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,042
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
You would just scan the array comparing the data at the current index and the next index with the new data to find where it goes in the array. Then just insert the data at that location. So you would want to use a for loop.
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:34 AM.


Advertisement
Log in to turn off these ads.