Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

templateclass Sort { private: int *index; public: Sort(){index=NULL;}; ~Sort(){d

ID: 3660671 • Letter: T

Question

templateclass Sort { private: int *index; public: Sort(){index=NULL;}; ~Sort(){delete []index;}; T * sortA(const T*,int,bool); T * sortA(const T*,int,int,int,bool); }; template T * Sort::sortA(const T* a,int ind1,int ind2,int col,bool ord) { index=new int[ind1]; T *sorted; for(int i=0; ia[index[j]*col]) { index[i]=index[i]^index[j]; index[j]=index[i]^index[j]; index[i]=index[i]^index[j]; } } } } if (ord==true) { for(int i=0;i<<"The start of Problem 2, the sorting problem"<<endl; Sort rc; bool ascending=true; ifstream infile; infile.open("Problem2.txt",ios::in); char *ch2=new char[10*16]; char *ch2p=ch2; while(infile.get(*ch2)){cout<<*ch2;ch2++;} infile.close(); cout<<endl; cout<<"Sorting on which column"<<endl; int column; cin>>column; cout<<endl; char *zc=rc.sortA(ch2p,10,16,column,ascending); for(int i=0;i<10;i++) { for(int j=0;j<16;j++) { cout<<zc[i*16+j]; } } delete []zc; cout<<endl; return 0; } Array: Lcekoeddhoffbmg Lkcmggjcdhhglif Cgldjhcekjigcdd Cgldjhcekjigcdn Bffmdbkcenlafjk Fggdijijegfblln Jjlncnimjldfedj Amliglfohajcdmm Balgfcaelhfkgeb Kmlhmhcddfoeilc Trying to sort on column #15 Lcekoeddhoffbmg Lkcmggjcdhhglif Cgldjhcekjigcdd Cgldjhcekjigcdn Bffmdbkcenlafjk Fggdijijegfblln Jjlncnimjldfedj Amliglfohajcdmm Balgfcaelhfkgeb Kmlhmhcddfoeilc Not sure why this is failing to compile

Explanation / Answer

your code is a bit messy so i can not follow it, hence i am giving you the code for column sort try to follow it and modify your code accordingly :) int getNumberOfColumns(const string& aline) { int ncols=0; istringstream ss(aline); string s1; while(ss>>s1) ncols++; return ncols; } vector getWordsFromSentence(const string& aline) { vectorwords; istringstream ss(aline); string tstr; while(ss>>tstr) words.push_back(tstr); return words; } bool findColumnName(vector vs, const string& colName) { vector::iterator it = find(vs.begin(), vs.end(), colName); if ( it != vs.end()) return true; else return false; } int getIndexForColumnName(vector vs, const string& colName) { if ( !findColumnName(vs,colName) ) return -1; else { vector::iterator it = find(vs.begin(), vs.end(), colName); return it - vs.begin(); } } ////////// I like the Recurssive functions - I tried to create a recursive function ///here. This worked for small values , say 20 rows. But for 55K - core dumps void sort2D(vectorvn, vector &srt, int columnIndex) { vector pVals; for ( int i = 0; i 1 ) { vn.erase(vn.begin()+(max_element(pVals.begin(), pVals.end())-pVals.begin()) ); vector vn2 = vn; //cout