Sort student names in ascending order

cout Sort student names in ascending order

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  #include<iostream>
#include<cstring>

using namespace std;

int main()
{
		
	char Names[5][20];
	
	for(int i =0 ; i <5;i++)
	{

	cout<<"Enter Your Desire Names: ";
	  cin>>Names[i];
	  
}



how to sort strings we have not read it yet but lab instructor give us assignment:(
Last edited on
I'd recommend using the powerful Google Search. if you googled for something like "sort strings C++" you'd have answer in no time.

Anyway, either google on how to use std::sort, or google quicksort/mergesort, although these are a bit harder.
i have understood this code

can someone write this code using loops only not strcmp and strcpy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<iostream>
#include<cstring>

using namespace std;

int main()
{
		
	char Names[5][20];
	char c[20];
	
	for(int i =0 ; i <5;i++)
	{

	cout<<"Enter Your Desire Names: ";
	  cin>>Names[i];
	  
}
   for(int i = 1 ; i < 5;i++)
   {
   	for(int j = 1 ; j <5;j++)
	   {
   		if(strcmp(Names[j-1], Names[j])>0){
   			strcpy(c , Names[j-1]);
   			strcpy(Names[j-1] , Names[j]);
   			strcpy(Names[j],c);
		   }
	   }
   }
   cout<<"Names In Alphabetical Order:\n";
   for(int i = 0 ; i <5;i++)
{
   		cout<<Names[i]<<"\n";
   }
}
Topic archived. No new replies allowed.