java - text data put into PQ heapsort -


i trying input data text file dynamic array , sort using pq heap sort program works regular 1-d array when using text file not work: here code

#include <iostream> #include<fstream> #include<string> using namespace std;  void swapdata(int&, int& );  class pqheapsort{  public:     pqheapsort(int datasize) : nindex(0) { pq = new int[datasize];}     ~pqheapsort() {delete[] pq; }     void insertdata(int);     int removedata();      void displaydata();     void bubbledown(int*, int, int);     void bubbleup (int*, int);  private:        int *pq;        int nindex; };  void pqheapsort::bubbleup(int a[], int bindex){     while (bindex>1 && a[bindex] < a[bindex/2]){        if(a[bindex] < a[bindex/2]){             swapdata(a[bindex], a[bindex/2]);}             bindex= bindex/2;      } }  void pqheapsort::bubbledown(int a[], int b, int c){     while (2*b <= c){         int child = 2*b;         if(child<c && a[child]>a[child+1]){             child++;         }         if (a[b]>a[child]) {             swapdata(a[b], a[child]);             b = child;         }         else return;     } }  void pqheapsort::insertdata(int item){         pq[++nindex] = item;        bubbleup(pq, nindex);  }  int pqheapsort:: removedata(){          swapdata(pq[nindex], pq[1]);         bubbledown(pq, 1, nindex-1);         return pq[nindex--];   }  void pqheapsort::displaydata(){     for(int = 1; i<=nindex; i++){         cout<<pq[i]<<" ";       }  }   void swapdata(int &a, int &b){     int tempdata = b;     b = a;     = tempdata;  }  int main() {     int arraysize = 0;     string inputfile;      ifstream infile;      cout << "please enter name of input file: ";     cin >> inputfile;     infile.open(inputfile.c_str());      int data;     while(infile>>data){         arraysize++;      }     int *textdata = 0 textdata = new int[arraysize];      for(int i=0; i<arraysize; i++){         infile>>textdata[i];         pqheapsort *q = new pqheapsort(arraysize-1);         q->insertdata(textdata[i]);         q->displaydata();         cout<<"min data remove"<< q->removedata()<<endl;         q->displaydata();      }             return 0; } 

how convert java


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -