Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 3rd, 2007, 03:57 PM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to sort an array ascending, help

Hy , this is my code, i am a beginner, i just want to make a program that will request an int array[10] and will rearange it asecenetly,
the problem seems easy to solve but is not.



#include <iostream>
using namespace std;

void v(int q[],int fc[]);

void main() {

    int i[10];
    int h[10];
    for (int a= 0;a<10;a++){
        cout<<"\n\t h["<<a<<"] = ";
        cin>> h[a];
    }
    v(h,i);
    for(a=0;a<10;a++){
        cout << "\n\t i["<<a<<"] ="<<i[a];
    }

}


void v(int ui[],int ui2[]) {

    int r;
    int s(0);
    for(int i=0;i<10;i++) {
        if(r<ui[i]) {
            r=ui[i];
        }
    }

    for(int y=9;y>-1;y--) {
        for (i=0;i<10;i++) {
            if((ui2[y]<ui[i]) && (ui2[y]<r)) { // *
                ui2[y] = ui[i]; s++;
            }
            r= ui2[y];cout<<"\n\t r="<<r; // **
        }
    }
    return;
}


* : the problem here : cannot see why the if statement functions in that manner, just compile it and see

** i just wrote taht to see at each loop ending if the r is well implemented , it is not, it should have been the last biggest number smaller than the preious biggest one

 
Old March 26th, 2007, 05:19 PM
Registered User
 
Join Date: Mar 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try using either brute force (search elements one at a time looking for largest then filling an array) or quicksort (standard C++).





Similar Threads
Thread Thread Starter Forum Replies Last Post
Listing dates ascending lgschulz VB.NET 2002/2003 Basics 1 December 19th, 2006 09:22 AM
parseInt - sort ascending crmpicco Javascript How-To 3 July 5th, 2005 09:13 AM
sort array of strings error lanita BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 December 14th, 2004 08:52 PM
Sort ascending and descending bertcox XSLT 1 May 17th, 2004 05:36 AM
array list sort linfakngiau BOOK: Beginning Java 2 2 October 19th, 2003 12:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.