bubble sort, void read functions? :/

well... heres my code first off:


#include <iostream>
#include <string>
#include <fstream>

using namespace std;

void Read(ifstream& inFile, int array[]);
void bubbleSort(int array[], int n);
void Print(int array[]);

const int SIZE = 25;

int main ()
{

int array[SIZE];

ifstream inFile;
inFile.open("a6.txt");

if (!inFile)
{
cout << "Cannot open file." << endl;
return 0;
}



system ("Pause");
}

void Read(ifstream& inFile, int array[])
{

int array[SIZE];
for (int counter = 0; counter < SIZE; counter++)
{
inFile >> array[counter];
}
}

void bubbleSort(int array[], int n)
{
bool swapped = true;
int j = 0;
int tmp;
while (swapped)
{
swapped = false;
j++;
for (int i = 0; i < n - j; i++)
{
if (array[i] > array[i + 1])
{
tmp = array[i];
array[i] = array[i + 1];
array[i + 1] = tmp;
swapped = true;
}
}
}
}



void Print(int array[])
{
for (int counter = 0; counter < 100; counter++)
cout << array[counter] << endl;
}


i can't figure this out and i don't know what i'm doing wrong.
can someone please just help me in the right direction??
honestly don't know what i'm doing
and if i can't get this done, i'm gonna have to drop the class.

could someone help?
thank you so much if you do.

i think my void read is wrong or something.
Please wrap your code in [code] blocks
closed account (1yvXoG1T)
code tags and a more specific question will get you a faster answer. I know you're trying to do a bubble sort but I can barely decipher your code with no indents and I don't know what you're specific problem is.
well i'm not sure what you mean by codes or tags but my overall problem is that this won't produce an output, and unless i'm connecting the functions wrong (or not at all) I honesty don't have a clue on where to go or what to do. I'm only looking for a hint to get me back in the right direction.
I know that the bubble sort function is right.

Basically I don't know if I am reading the file into an array right, and using that array effectively.
Edit your original post, and put [code] and closing tag around your code so it gives it syntax highlighting. Please ensure it's also nicely formatted for us to read. As it is now, it's not easy for us to read your code to help you
i understand thank you
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

void Read(ifstream& inFile, int array[]);

void bubbleSort(int array[], int n);

void Print(int array[]);

const int SIZE = 25;

int main ()
{

     int array[SIZE];

     ifstream inFile;
     inFile.open("a6.txt");

     if (!inFile)
{
     cout << "Cannot open file." << endl; 
     return 0;
}



     system ("Pause");
}

void Read(ifstream& inFile, int array[]) 
{

     int array[SIZE];

     for (int counter = 0; counter < SIZE; counter++)
{
     inFile >> array[counter];
}

}

void bubbleSort(int array[], int n) 
{
     bool swapped = true;
     int j = 0;
     int tmp;

     while (swapped) 
{
     swapped = false;
     j++;

     for (int i = 0; i < n - j; i++) 
{
     if (array[i] > array[i + 1]) 
{
     tmp = array[i];
     array[i] = array[i + 1];
     array[i + 1] = tmp;
     swapped = true;
     }
    }
  }
}



void Print(int array[])
{
     for (int counter = 0; counter < 100; counter++)

     cout << array[counter] << endl;
}


Hopefully that is better?

forgot to say, obviously the .txt file is just a bunch of numbers that I need to have sorted with the bubble sort function.
closed account (D80DSL3A)
The main problem is that none of your functions are being called. In main() after line 27 it is time to call Read(), bubbleSort() then Print().
Topic archived. No new replies allowed.