Bubblesort issue

please give the code to apply bubblesort in 2d arrays of strings

what is the significance of cin ignore what happens if we do not use it

Hello @Rj.25

The code below won’t work without cin.ignore();
Give the below a try with and without the cin.ignore() statement

Ignore is exactly what the name implies.
It ignores the amount of characters you specify when you call it, up to the char you specify as a breakpoint.

It works with both input and output buffers.

Essentially, for std::cin statements you use ignore before you do a getline call, because when a user inputs something with std::cin, they hit enter and a ‘\n’ char gets into the cin buffer. Then if you use getline, it gets the newline char instead of the string you want. So you do a std::cin.ignore(1000,’\n’) and that should clear the buffer up to the string that you want. (The 1000 is put there to skip over a specific amount of chars before the specified break point, in this case, the \n newline character.)

what happens if we use key==a[i] in place of strcmp function?

Hello @Rj.25

Here is the code to sort the array of strings using bubble sort

Hello @Rj.25

The strcmp function returns
0 if both the strings (s1 & s2) are same
1 if s1 is greater than s2 in dictionary order
-1 if s1 is smaller then s2 in dictionary order

while if you use key == a[i] it will return
1 if both the strings are same
0 if they are NOT
So then you will have to use if key > a[i] OR key < a[i] also.