Bubble Sort C-String

Hey guys I'm encountering an error when trying to sort char * (C-strings). I'm not really sure what it is. Hoping someone can guide me.

1
2
3
4
5
6
7
8
9
   void bubbleSort(char *arr, int n) {
          for (int last = n-1; last > 0; last--) {
                  for (int i = 0; i < last; i++)
                          if (arr[i] > arr[i+1])
                                  swap(arr[i], arr[i+1]);
          }
  }
Input : 'Z''M''A''L''Q''P''G''T''B''F'
Output : ' ' ' ' ' ' ' A M Z 


1
2
3
4
5
6
7
8
void bSort(char *arr, int n) {	
	for (int i = 0; i<n; i++) {
		for (int j =i+1; j < n; j++)
			if (arr[i] > arr[j])
				std::swap(arr[i], arr[j]);
	}
return;          
}
Topic archived. No new replies allowed.