Bubble sorting of array

Hi guys,

need a bit help with sorting of array. I have this code, but for some reason it does not sort the list. Can anybody explain what I am doing wrong

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

void sort (int list[], int size);
void print (int list[], int size);


int main()
{
int size;
int list[] = {3,4,3,2,4,5,7,4,7,8,4,4,3,2,4,7,8,5,4,3,3,3,4,5,5};

cout << "Our unsorted list is: ";
print(list, 25);
cout << endl;

sort(list, 25);
cout << "Our sorted list is: ";
print(list, 25);

return 0;
}

void sort(int list[], int size)
{
size = sizeof(list)/sizeof(int);
for (int i= size; i>1; i-- )
{
for (int j = 1; j<i; j++)
{
if (list[j-1]< list[j])
{
swap (list[j-1], list[j]);
}
}
}
}

void print (int list[], int size)
{
for (int n=0; n< size; n++)
cout << setw(2) << list[n];
cout << endl;
}
1
2
void sort(int list[], int size) {
size = sizeof(list)/sizeof(int);

Why do you get value for size from user and immediately overwrite it?
@Shinigami Good answer.

Actually that particular line of code would be much more beneficial in main() where it would avoid the need for manually counting the size of the array and typing the value into three separate function calls.
Thank you guys. Fresh eyes helped. I see my mistake now. It kept throwing me into infinite loop and I played around with code and I think messed it out completely.
It works. thank you for your help again
Topic archived. No new replies allowed.