How do you use the bubble sort in this program:
#include <iostream>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
for (int i = 0; i < argc; i++)
cout << argv[i] << endl;
cout << "argv[5] changed to an int is " << atoi(argv[5]);
cout << "argv[6] changed to an int is " << atoi(argv[6]);
for (int i = 0; i < argc-1; i++)
if (strcmp(argv[i], argv[i+1]) > 0)
{
char *x = argv[i];// temporarly point to argv[i]
argv[i] = argv[i+1];// argv[i] now points to same place as argv[i+1]
argv[i+1] = x;// argv[i+1] now points to old argv[i]
}
// I think you bubble sort function here.
// And then use the function strcmp to switch strings, but how?
for (int i = 0; i < argc; i++)
cout << argv[i] << endl;
system("PAUSE");
return 0;
}
// argc is a double pointer
// *argv array of character arrays