Important alert: (current site time 7/15/2013 5:54:59 PM EDT)
 

VB icon

Ascend Array

Email
Submitted on: 4/21/2004 3:26:21 AM
By: arwen  
Level: Beginner
User Rating: By 1 Users
Compatibility: C++ (general)
Views: 10907
 
     This code sorts an integer array in ascending order
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :Ascend Array
//**************************************
-
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Ascend Array
// Description:This code sorts an integer array in ascending order
// By: arwen
//
// Inputs:Just enter 10 numbers
//
// Returns:-
//
// Assumes:-
//
// Side Effects:-
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=7858&lngWId=3//for details.//**************************************

//author : vijayalakshmi
//vote for me.....=)
//taking 10 numbers from the user and sort them in ascending order
#include <iostream.h>
void getData();
void sortData();
void dispData();
int num[10];
void main()
{
	getData();
	sortData();
	dispData();
}
void getData()
{
	int ctr;
	ctr=0;
	
	//Enter 10 Numbers
	while(ctr<10)
	{
		cout<<"Enter a Number"<<endl;
		cin>>num[ctr];
		ctr++;
	}
}
void sortData()
{
	int ctr=0;
	
	//sorting the array according to the values
	while(ctr<9)
	{
		int temp;
		if(num[ctr]>num[ctr+1])	//comparing the value of the current element with the next
		{
			//swap the values
			temp=num[ctr];
			num[ctr]=num[ctr+1];
			num[ctr+1]=temp;
			ctr=0;
			continue;
		}
		ctr++;
	}
}
void dispData()
{
	cout<<endl<<endl<<"Sorted Array"<<endl<<endl;
	
	//display all the numbers in the array
	for(int ctr=0;ctr<10;ctr++)
	{
		cout<<num[ctr]<<endl;
	}
}


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

4/21/2004 2:11:24 PMSeth McDowell

The use of is old and non-standard, you use a global variable (integer array) and you use "void main" which is also non-standard. Also, you spammed the same code on p-s-c 4, I repeat FOUR, times!!!
(If this comment was disrespectful, please report it.)

 
1/16/2005 1:27:25 AM

its nice to have a web site like this atleast we cn learn more about programming even though were not programmers..
(If this comment was disrespectful, please report it.)

 
1/16/2005 1:33:01 AM

please can you send me the code of this program??? "if the user press 1 the program will prompt the user to enter character to be pushed on the stack. if the user press 2 the last element from the stack will be removed. if the user press 3 display the output. if 4 the program will terminate.." tnx
(If this comment was disrespectful, please report it.)

 
8/4/2006 11:19:46 PMLAMBOFGOD

Slopy
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.