1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

About arrange in array

Discussion in 'C' started by aoine, Nov 17, 2010.

  1. aoine

    aoine New Member

    Joined:
    Nov 17, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi everyone :), I'm training on C++ language and I have some troubles about array. My problem is arranging in array. Example, I have an float array, I wanna sort my negative numbers descending on the left, the zero (0) numbers in the middle and positive number ascending on the right in three ways: selection sort, insert sort and bubble sort. I hope you spare a little time to help me.

    Code:
    #include	<stdio.h>
    #include	<conio.h>
    #include	<iostream.h>
    
    void input(int *a, int n)
    {
    	for(int i=0;i<n;i++)
    	{	cout << "a[" << i << "]= ";
    		cin >> a[i];
    	}
    }
    
    void output(int *a,int n)
    {
    	for(int i=0;i<n;i++)
    	{
    		cout << a[i] << "\t";
    	}
    }
    
    void swap(int &a,int &B)
    {
    	int tmp=a;
    	a=b;
    	b=tmp;
    }
    
    void main()
    {
    	clrscr();
    	int n;
    	int *a;
    	cout << "Enter numbers of array: ";
    	cin >> n;
    	input(a,n);
    	output(a,n);
    	getch();
    }
    
    Thanks in advance and have a nice day.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Hi, welcome to the vast world of programming. Two of the most essential tools you need are Google and Wikipedia. Googling each type of sort - for me - returned a well written Wiki article as the top hit; here are the links:

    http://en.wikipedia.org/wiki/Bubble_sort
    http://en.wikipedia.org/wiki/Insertion_sort
    http://en.wikipedia.org/wiki/Selection_sort

    Also make sure you read IN FULL and act on this one:
    http://www.catb.org/~esr/faqs/smart-questions.html
    If you ask questions as outlined here you can be sure to get quality help.
    This is a great article. I'm going to put it in my sig, if I can.
     
    Last edited: Nov 18, 2010

Share This Page