Simple enough. Been doing exercises for days to brush up for next term and this one (selectionSort func followed by sequentialSearch) keeps giving me error:
Unresolved External...???
Code:
#include <iostream>
using namespace std;
const int A_S = 10;
int seqSearch(const int list[], int listLength, int searchItem);
void selectionSort (int list[], int length);
int main()
{
int list[] = {2, 56, 34, 25, 73, 46, 89, 10, 5, 16};
int i;
int index;
int number;
selectionSort(list, 10);
cout << "After sorting, the list elements are:" << endl;
for (i = 0; i < 10; i++)
cout << list[i] << " ";
cout << "Enter the number to be searched: ";
cin >> number;
cout << endl;
index = seqSearch(list, A_S, number);
if (index != -1)
cout << number << " is found at position " << index << "." << endl;
else
cout << number << " is not in the list." << endl;
return 0;
}
void selctionSort (int list[], int length)
{
int index;
int smallestIndex;
int minIndex;
int temp;
for (index = 0; index < length - 1; index++)
{
smallestIndex = index;
for (minIndex = index + 1; minIndex < length; minIndex++)
if (list[minIndex] < list[smallestIndex])
smallestIndex = minIndex;
temp = list[smallestIndex];
list[smallestIndex] = list[index];
list[index] = temp;
}
}
int seqSearch(const int list[], int listLength, int searchItem)
{
int loc;
bool found = false;
for (loc = 0; loc < listLength; loc++)
if (list[loc] == searchItem)
{
found = true;
break;
}
if (found)
return loc;
else
return -1;
}