Important alert: (current site time 7/15/2013 5:52:58 PM EDT)
 

VB icon

A simple strings sorting

Email
Submitted on: 4/13/2002 9:31:53 AM
By: Tahseen 
Level: Beginner
User Rating: By 5 Users
Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++
Views: 48112
(About the author)
 
     This code will make you understand simple by accepting 4 strings and sorting it through Bubble sort i trust this u help for C and C++ Beginner.
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :A simple strings sorting
//**************************************
#include <iostream.h>
#include <string.h>
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: A simple strings sorting
// Description:This code will make you understand simple by accepting 4 strings and sorting it through Bubble sort i trust this u help for C and C++ Beginner.
// By: Tahseen
//
// Inputs:Ask to enter 4 strings
//
// Returns:returns sorting strings
//
// Assumes:User should be aware of Arrays, boolean,for loops.
//
// Side Effects:Not much its only like beginiing of C and C++ Programer
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=3714&lngWId=3//for details.//**************************************

#define ELEMENT 4
#define LENGTH 20
void getdata(char str[ELEMENT][LENGTH]);
void show(char str[ELEMENT][LENGTH]);
void sort(char str[ELEMENT][LENGTH]);
void main()
{
char str[ELEMENT][LENGTH];
cout<<"Find the sortin of string\n";
getdata(str);
sort(str);
show(str);
}
void getdata(char str[ELEMENT][LENGTH])
{
int loop;
for(loop=0;loop<ELEMENT;loop++)
{
	cin.getline(str[loop],LENGTH);
}
}
void sort(char str[ELEMENT][LENGTH])
{
char temp[LENGTH];
int loop;
bool flag;
do
{
 flag=false;
 for(loop=0;loop<ELEMENT;loop++)
 {
 	if(strcmp(str[loop],str[loop+1])>0)
 {
 	flag=false;
 strcpy(temp,str[loop]);
 strcpy(str[loop],str[loop+1]);
 strcpy(str[loop+1],temp);
 flag=false;
 }
 }
}while(flag!=false);
}
void show(char str[ELEMENT][LENGTH])
{
int loop;
cout<<endl;
for(loop=0;loop<ELEMENT;loop++)
{
	cout<<str[loop]<<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

5/29/2002 11:51:18 PMRush2Sun

if(strcmp(str[loop],str[loop+1])>0)
{
flag = true;
.
.
.
//flag = false;
}
(If this comment was disrespectful, please report it.)

 
5/31/2002 1:16:34 AMSarmen BB

dont people know the diff between C++ and C? this is a C++ coding here.


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

 
6/26/2003 8:20:46 AM

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

 
7/25/2003 11:06:53 PM

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

 
12/28/2003 1:05:46 PMSAJIN SV

This is a good code..But As i dont know C++ could u plz convert this to C
(If this comment was disrespectful, please report it.)

 
11/13/2006 12:03:07 AMcorey

if you know c theres only a few things to make this a whole c program very simple
(If this comment was disrespectful, please report it.)

 
12/18/2006 1:23:38 AMDheeraj Mehrotra

Wonderful Logic. No comments. Keep the good work on.
(If this comment was disrespectful, please report it.)

 
2/26/2007 2:49:17 AMvenugopal

sir i have a degree .. and i collect u r most datastructures programs .it is good opportunity to all
Thank QQQQQQ Sir
(If this comment was disrespectful, please report it.)

 
5/27/2009 2:11:35 AMFattah

little bit confused with this code cause i've never used iostream.h. but i think i can get the general understanding of this code. good job Mr. Tahseen...
(If this comment was disrespectful, please report it.)

 
8/10/2010 11:07:55 PM

how can i get iostream.h?
(If this comment was disrespectful, please report it.)

 
1/5/2011 9:26:36 PMAsim Fani

thns SIR ..4 ur cooperation
(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.