0

I'm getting this error while executing a simple program for implementing the Quick Union Algorithm. I couldn't find anything wrong with the curly braces. I have posted the code below. Kindly review it.

#include <iostream>
#include <fstream>

#ifdef _WIN32
#define WINPAUSE system("pause")
#endif
#include <cstdio>
#include <ctime>
using namespace std;

class QuickUnionUF
{
private:
    int arr[9000];

public:
    QuickUnionUF()
    {
        for (int k = 0; k < 9000; k++)
            arr[k] = k;
    }

public:
    int find_root(int i)
    {
        while (i != arr[i])
            i = arr[i];
        return i;
    }

public:
    bool connected(int p, int q)
    {
        if (find_root(p) == find_root(q))

            return true;
        else
            return false;
    }

public:
    void union_function(int p, int q)
    {

        int i = find_root(p);
        int j = find_root(q);
        arr[i] = j;
    }
};

int main()
{

    clock_t start = clock();
    //int id[9000];
    //for (int i = 0; i < 9000; i++)
    //  id[i] = i;
    const char* filename = "mine";
    ifstream inFile(filename);

    int p, q;

    if (!inFile) {
        cout << endl
             << "File cannot be opened " << filename << "\n";
        return 1;
    }

    QuickUnionUF QU = QuickUnionUF();

    int select;

    while (!inFile.eof())
    {
        inFile >> p;
        inFile >> q;
        cout << "elemnets taken :" << p << " " << q << " ";

        //cout << " " << p;// << " " << q;
        if (QU.connected(p, q)) {
            cout << "already connected \n";
            continue;
        }

        else {
            QU.union_function(p, q);
            cout << "connectin" << p << " " << q << " \n";
        }
    }

    inFile.close();

    clock_t end = clock();
    double time = ((double)(end - start)) / CLOCKS_PER_SEC;
    cout << endl
         << "time " << time << endl;

    cout << "\n";

    return 0;
}
drescherjm
  • 8,907
  • 5
  • 42
  • 60
  • Not related to the compiler error however important: http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong – drescherjm Feb 03 '17 at 04:13
  • your code compile just fine. But I tested in windows, Visual Studio. Not the brackets are the problem. – alex.pulver Feb 03 '17 at 07:42

0 Answers0