Problem solved! Thanks.

I keep getting this error: error C3409: empty attribute block is not allowed
along with error C2144: syntax error : 'int' should be preceded by ']'

This is my code.
#include <iostream>
#include<cstdlib>
using namespace std;

void fill(int[],int []);
void bubbleSort(int [],int);
void selectionSort(int [],int);
int searchList (int [],int);
int binarySearch(const int [],int, int);

void fill (int array1 [],[int array2 [])
{
int random;
for (int i=0; i < 20; i++)
{
random = 1+rand() % 20;
array1[i]=random;
}

}
void bubbleSort(int array1[],int size)
{
bool swap;
int temp;

do
{
swap = false;
for (int count = 0; count < (size - 1); count++)
{
if (array1[count] > array1[count + 1])
{
temp = array1[count];
array1[count] = array1[count+1];
array1[count+1] = temp;
swap = true;
}
}
} while (swap);
}

void selectionSort(int array2[], int size)
{
int startScan, minIndex, minValue;

for (startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minValue = array2[startScan];
for (int index = startScan + 1; index < size; index++)
{
if (array2[index] < minValue)
{
minValue = array2[index];
minIndex = index;
}
}
array2[minIndex] = array2[startScan];
array2[startScan] = minValue;
}
}

int searchList (int array1[], int selection)
{
int index = 0;
int position = -1;
bool found = false;

while (index < 20 && !found)
{
if (array1[index] == selection)
{
found = true;
position = index;
}
index++;
}
return position;
}
int binarySearch (int array1[], int size, int selection)
{
int first =0,
last = size - 1,
middle,
position = -1;
bool found = false;

while(!found && first <= last)
{
middle = (first + last) / 2;
if (array1[middle] == selection)
{
found = true;
position = middle;
}
else if (array1[middle] > selection)
last = middle - 1;
else
first = middle + 1;
}
}


int main()
{
int result;
int selection;
int array1[20];
int array2[20];
fill(array1,array2);
for (int n=0; n < 20; n++)
{
array2[n]=array1[n]; //This might be simply assigning values, not copying them. Double-check.
}
bubbleSort(array1);
selectionSort(array2);
cout << "Enter a number you would like to search for within the array. " << endl;
cin >> selection;
result = searchList(array1,selection);
cout << "The element has been found. It is located in array one at position " << result << endl;
result = binarySearch(array1, selection);
cout << "The element has been found. It is located in array one at position " << result << endl;

cout << "The contents of array 1: " << endl;
for (int n=0; n < 20; n++)
{
cout << array1[n] << endl;
}
cout << "The contents of array 2: " << endl;
for (int n=0; n < 20; n++)
{
cout << array2[n] << endl;
}
return 0;
}
Last edited on
which line?

please use code tag .

see the icon <>
void fill (int array1 [],[int array2 [])

You have a dangling bracket (typo?)
A dangling bracket where?
Last edited on
1
2
void fill (int array1 [],[int array2 [])
                         ^


Right there.
Thanks!! That was the problem. Typo screwed me up! Thanks guys! Very much appreciated!
Topic archived. No new replies allowed.