I've been trying for hours now trying to get this to work and I think I have hit a brick wall. It's pretty frustrating!
I have a database, with a table within it named files. I query this table with this query:
SELECT f.FileID, f.File_Name FROM File f LEFT JOIN Stats s ON f.FileID = f.FileID AND s.UserID = "+ userid + " WHERE s.FileID IS NULL
SELECT f.FileID, f.File_Name FROM File f LEFT JOIN Stats s ON f.FileID = f.FileID AND s.UserID = "+ userid + " WHERE s.FileID IS NULL
To copy to clipboard, switch view to plain text mode
I then want to sort the data by filename (using my quicksort) and populate a combo box with the sorted filenames
My quicksort consists of this:
quicksort.h
#ifndef QUICKSORT_H
#define QUICKSORT_H
class QuickSort
{
public:
char *FileNames[1000];
void QuSort(int left, int right);
int partition(int left, int right);
void swap(int a, int b);
};
#endif // QUICKSORT_H
#ifndef QUICKSORT_H
#define QUICKSORT_H
class QuickSort
{
public:
char *FileNames[1000];
void QuSort(int left, int right);
int partition(int left, int right);
void swap(int a, int b);
};
#endif // QUICKSORT_H
To copy to clipboard, switch view to plain text mode
quicksort.cpp
#include "quicksort.h"
#include <cstring>
using namespace std;
void QuickSort::QuSort(int left, int right)
{
int p;
if(left>=right)
return;
p = partition(left, right);
QuSort(left,p-1);
QuSort(p+1,right);
}
int QuickSort::partition(int left, int right)
{
int first,pivot;
first = left;
pivot = right--;
while(left<=right)
{
while(strcmp(FileNames[left],FileNames[pivot]) < 0)
left++;
while( (right>=first) && (strcmp(FileNames[right],FileNames[pivot])>=0) )
right--;
if(left<right)
{
swap(left,right);
left++;
}
}
if(left!=pivot)
swap(left,pivot);
return left;
}
void QuickSort::swap(int a, int b)
{
char *temp;
temp=FileNames[a];
FileNames[a]=FileNames[b];
FileNames[b]=temp;
}
#include "quicksort.h"
#include <cstring>
using namespace std;
void QuickSort::QuSort(int left, int right)
{
int p;
if(left>=right)
return;
p = partition(left, right);
QuSort(left,p-1);
QuSort(p+1,right);
}
int QuickSort::partition(int left, int right)
{
int first,pivot;
first = left;
pivot = right--;
while(left<=right)
{
while(strcmp(FileNames[left],FileNames[pivot]) < 0)
left++;
while( (right>=first) && (strcmp(FileNames[right],FileNames[pivot])>=0) )
right--;
if(left<right)
{
swap(left,right);
left++;
}
}
if(left!=pivot)
swap(left,pivot);
return left;
}
void QuickSort::swap(int a, int b)
{
char *temp;
temp=FileNames[a];
FileNames[a]=FileNames[b];
FileNames[b]=temp;
}
To copy to clipboard, switch view to plain text mode
Then when a user selects a filename from down box and presses a button I have another query which updates the database, this query looks like this:
INSERT INTO stats (`UserID`, `FileID`, `Completed`) VALUES ('"+ userid +"', '"+fileid+"', 'No');
INSERT INTO stats (`UserID`, `FileID`, `Completed`) VALUES ('"+ userid +"', '"+fileid+"', 'No');
To copy to clipboard, switch view to plain text mode
Finally the combo box is updated to remove the fileid which has been added to the table within the database.
The problems I face are:
1) I don't know how to sort the query results i get (with my quicksort) and keep the file names linked to the File Id
2) I don't know how to populate the combo box with my the query results
3) I don't know how to obtain the fileid of a sorted item highlighted in the combo box
I'm required, by my lecturer, to use my own quicksort function, so i cannot use a function already avaliable to me.
Please could someone help me
Thanks very much for your time and trouble
Bookmarks