Advertisement
ASP_Volume3 Sorting #58724

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

ملخص الذكاء الاصطناعي: 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.

كود المصدر
original-source
#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