| danielZX (3) | |
|
Hi, I am new in C++ programming. I got a question that I don't know how to answer. It is about sorting two dimensional arrays. So here is the question. I must create a code that it can accept 5 names and sort in both ascending and descending order. The thing is I don't know how to sort it in 2 Dimensional array. So please I need your help. Thanks. Here is the code i done so far: //bubble sort alphabets #include<iostream> using namespace std; void main() { char arr[5][20]; int swap; cout<<"Enter 5 alphabets\n"; for(int i=0;i<5;i++) cin>>arr[i]; for (int i=0 ; i<5; i++) { for (int j=0; j < 5 - i - 1; j++) { if (arr[j] > arr[j+1]) { swap = arr[j]; arr[j] = arr[j+1]; arr[j+1] = swap; } } } cout<<"Sorted list in ascending order:\n"; for (int i = 0 ; i < 5 ; i++ ) cout<<arr[i]<<endl; system("pause"); } Please help in creating a 2D(2 dimensional array) code. Oh,if I am in the wrong topic please tell where should I post this question to get help.Thank you and God Bless. | |
|
|
|
| cire (2347) | |
| Why don't you use an array of strings instead of a two dimensional array? | |
|
|
|
| danielZX (3) | |
|
But i need to arrange them . I need to accept 5 different names and arrange them with their first alphabet. | |
|
Last edited on
|
|