Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,252 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,142 people online right now. Registration is fast and FREE... Join Now!




Arranging Intergers from large to small

 
Reply to this topicStart new topic

Arranging Intergers from large to small, is it possible without an array?

overclocked
post 12 Mar, 2008 - 04:09 PM
Post #1


New D.I.C Head

*
Joined: 24 Oct, 2007
Posts: 27


My Contributions


I was wondering if you can arrange integers without an array.(I know you can with an array) I'm trying to finish the last part of my program and I noticed my integers were not arrays so I couldn't arrange with my previous code.

Which was this
cpp
for (x=0; x<20; x++)		//In loop
{
cout <<"Enter your number: " << endl;
cin >>array[x];
}
cout <<endl<<endl;
cout <<"Numbers in ascending order: ";
for (x=0; x<20; x++)
{
for (w=0; w<20; w++)
{
if (array[w] > array[w+1]) // Sort loop
{
temp = array[w];
array[w] = array [w+1];
array[w+1] = temp;
}
}
}


I only need to arrange 5 numbers but I tried taking the same idea thats with the array but it doesn't work. Any help? I'm really not trying to rewrite the whole program... cool.gif
User is offlineProfile CardPM

Go to the top of the page

KYA
post 12 Mar, 2008 - 04:25 PM
Post #2


#include <nerd.h>

Group Icon
Joined: 14 Sep, 2007
Posts: 4,205



Thanked 48 times

Dream Kudos: 1150
My Contributions


yes, but you'd have to define the sort function yourself though
User is online!Profile CardPM

Go to the top of the page

NickDMax
post 12 Mar, 2008 - 06:16 PM
Post #3


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,857



Thanked 47 times

Dream Kudos: 550
My Contributions


ooo neat challenge problem: Arrange an arbitrary list of numbers without the use of a typical data structure.

Well, basically you will need to use SOME structure to hold the data (even if it is just 5 variable a1, a2, a3... etc). Now there are LOTS of data structures you can choose from (linked lists, stacks, queues, trees... just to name a few). But you don't even really have to use a data structure as you can use logical program structures as well...

To arrange 5 numbers the easiest method I can think of is a little loop with an if-else-if statement...
User is offlineProfile CardPM

Go to the top of the page

NickDMax
post 12 Mar, 2008 - 06:50 PM
Post #4


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,857



Thanked 47 times

Dream Kudos: 550
My Contributions


ok... I take that back.. the easiest method I could think of just uses a set of if-statements.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 10:39PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month