So with my program I'm trying to count the number of operations it takes to perform a insertion sort/quick sort. And because functions are calling other functions from inherited classes, it gets a bit confusing as to where I can place the operation to increment the number of operations. Right now my code is trying to compile but keeps getting the error saying that void InsertionSort::insertionsort(long*const, int) is being referenced someplace else--and it is because another function returns numops without going through the insertionsort function.

Here's what I mean..

Header file:

#ifndef INSERTIONSORT_H
#define INSERTIONSORT_H

#include "SortData.h"

class InsertionSort : public SortData
{
public:
	InsertionSort(int max=100);
	~InsertionSort(void);
	_int64 sort();

private:
	_int64 numops;
	void insertionsort(long theArray[], int n);
};

#endif

Implementation file:

_int64 InsertionSort::sort()
{
	numops = 0;
	insertionsort(theData, maxSize);
	return(numops);
}

void insertionsort(long theArray[], int n)
{
	int i, j, key;
	_int64 numops = 0;
    for(j = 1; j < n; j++)    
    {
		key = theArray[j];
        for(i = j - 1; (i >= 0) && (theArray[i] < key); i--)   
        {
			theArray[i+1] = theArray[i];
			numops =+ 1;
        }
		
		theArray[i+1] = key;    
     }
}

And the main.cpp

void test(SortData& ad, bool print=false)
{
	ad.randomize();
	if(print)
	{
		cout << "Unsorted Dataset size(" << ad.size() << "):" << endl;
		ad.printSome();
	}

	_int64 num = ad.sort();
	if(print)
	{
		cout << "Sorted Dataset size(" << ad.size() << "):" << endl;
		ad.printSome();
	}

	cout << "Dataset Size= " << setw(8) << ad.size();
	cout << " Num Ops = "<< num << endl;
}

Here's the error code:

Error	1	error LNK2019: unresolved external symbol "private: void __thiscall InsertionSort::insertionsort(long * const,int)" (?insertionsort@InsertionSort@@AAEXQAJH@Z) referenced in function "public: virtual __int64 __thiscall InsertionSort::sort(void)" (?sort@InsertionSort@@UAE_JXZ)	C:\Users\Joseph\documents\visual studio 2010\Projects\CSC2431 Sorting Efficiency\CSC2431 Sorting Efficiency\InsertionSort.obj	CSC2431 Sorting Efficiency
Error	2	error LNK2019: unresolved external symbol "private: void __thiscall QuickSort::quicksort(long * const,int)" (?quicksort@QuickSort@@AAEXQAJH@Z) referenced in function "public: virtual __int64 __thiscall QuickSort::sort(void)" (?sort@QuickSort@@UAE_JXZ)	C:\Users\Joseph\documents\visual studio 2010\Projects\CSC2431 Sorting Efficiency\CSC2431 Sorting Efficiency\QuickSort.obj	CSC2431 Sorting Efficiency

Can someone help me please? This is the last thing that's keeping the code from compiling fully. Argh...

Thanks all!!

J

In your implementation file you have forgotten

void InsertionSort::insertionsort(long theArray[], int n)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.