A simple strings sorting
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.
AI
AIサマリー: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
ソースコード
#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;
}
}
オリジナルのコメント (3)
Wayback Machineから復元