gobigred04
10-17-2005, 05:24 PM
I need some help with some C++ code for a class. I was sick for most of the lecture on this so i just need a little boost with the code to see what's going on. All i have so far is what I got from another student;the teacher i'm sorry to say is worthless and almost refuses to help. Any help would be very very appreciated.
Unlike normal quicksort's wherein you use an array to classify the numbers, he wants a tree_insert type statement. Please help!!
Okay, you might want to shield your eyes!
#include <iostream>
using namespace std;
template<class T>
class quicksort
{
public:
void Insert(Tx){head=tree_insert(head,x)};
private:
};
struct r
{
r * lp;
int pivot;
r * rp;
};
r * head;
template<class T>
quicksort<T>::r * quicksort<T>::tree_insert( r * h, Tx)
{
r * temp;
{
if(head==NULL)
{
temp = new(r);
temp -> lp = NULL;
temp -> pivot= x;
temp -> rp = NULL;
return temp;
}
if(x>h->pivot)h->rp=tree_insert(h->rp,x);
else
h->lp=tree_insert(h->lp,x);
return h;
};
int main(){
// this would contain something along the lines of
//head=tree_insert(head,2);
}
print(r * h)
{
if(h!=NULL)
{
print(h->lp);
cout<<h->pivot);
print(h->rp);
}
Unlike normal quicksort's wherein you use an array to classify the numbers, he wants a tree_insert type statement. Please help!!
Okay, you might want to shield your eyes!
#include <iostream>
using namespace std;
template<class T>
class quicksort
{
public:
void Insert(Tx){head=tree_insert(head,x)};
private:
};
struct r
{
r * lp;
int pivot;
r * rp;
};
r * head;
template<class T>
quicksort<T>::r * quicksort<T>::tree_insert( r * h, Tx)
{
r * temp;
{
if(head==NULL)
{
temp = new(r);
temp -> lp = NULL;
temp -> pivot= x;
temp -> rp = NULL;
return temp;
}
if(x>h->pivot)h->rp=tree_insert(h->rp,x);
else
h->lp=tree_insert(h->lp,x);
return h;
};
int main(){
// this would contain something along the lines of
//head=tree_insert(head,2);
}
print(r * h)
{
if(h!=NULL)
{
print(h->lp);
cout<<h->pivot);
print(h->rp);
}