-5

here is my code from which can't understand where is error

#include <iostream>
#include<iomanip>
using namespace std;
#define narray 8;// array size;
#define  nbucket 5;// bucket size;
#define interval 10;// bucket range
struct node
{
int data;
struct node *next;
};
void BucketSort(int arr[]);
struct node *InsertionSort(struct Node *list);
void print(int arr[]);
void printBuckets(struct Node *list);
int getBucketIndex(int value);
void BucketSort(int arr[])
{

 int i,j;
 struct node **buckets;
 buckets = (struct node **)malloc(sizeof(struct node*) * nbucket); 
 for (i=0;i<nbucket;i++){
      buckets[i]=NULL;
 }
 for (int i=0;i<narray;i++){
  struct node *current;
  int pos=getBucketIndex(arr[i]);
  current=(struct node *)malloc(sizeof(struct node));
  current->data=arr[i];
  current->next=buckets[pos];
  buckets[pos]=current;


 }

}


int main(){





 return 0;
}

errors are a lot of,for example

Error   1   error C2143: syntax error : missing ')' before ';'  c:\documents and settings\student\my documents\visual studio 2008\projects\bucket_sort\bucket_sort\bucket_sort.cpp  22  bucket_sort
Error   2   error C2059: syntax error : ')' c:\documents and settings\student\my documents\visual studio 2008\projects\bucket_sort\bucket_sort\bucket_sort.cpp  22  bucket_sort
Error   3   error C2146: syntax error : missing ')' before identifier 'i'   c:\documents and settings\student\my documents\visual studio 2008\projects\bucket_sort\bucket_sort\bucket_sort.cpp  23  bucket_sort
Error   4   error C2059: syntax error : ';' c:\documents and settings\student\my documents\visual studio 2008\projects\bucket_sort\bucket_sort\bucket_sort.cpp  23  bucket_sort
Error   5   error C2059: syntax error : ')' c:\documents and settings\student\my documents\visual studio 2008\projects\bucket_sort\bucket_sort\bucket_sort.cpp  23  bucket_sort
Error   6   error C2143: syntax error : missing ';' before '{'  c:\documents and settings\student\my documents\visual studio 2008\projects\bucket_sort\bucket_sort\bucket_sort.cpp  23  bucket_sort
Error   7   error C2146: syntax error : missing ')' before identifier 'i'   c:\documents and settings\student\my documents\visual studio 2008\projects\bucket_sort\bucket_sort\bucket_sort.cpp  26  bucket_sort
Error   8   error C2059: syntax error : ';' c:\documents and settings\student\my documents\visual studio 2008\projects\bucket_sort\bucket_sort\bucket_sort.cpp  26  bucket_sort
Error   9   error C2059: syntax error : ')' c:\documents and settings\student\my documents\visual studio 2008\projects\bucket_sort\bucket_sort\bucket_sort.cpp  26  bucket_sort
Error   10  error C2143: syntax error : missing ';' before '{'  c:\documents and settings\student\my documents\visual studio 2008\projects\bucket_sort\bucket_sort\bucket_sort.cpp  26  bucket_sort
Rohit Vipin Mathews
  • 11,629
  • 15
  • 57
  • 112
  • Regretfully I did not use Stackoverflow when it was the time of the 15 pages long errors when using templates. Otherwise I could have stuck the site with compilation error logs. – Boris Strandjev Mar 06 '12 at 10:58
  • atleast try to follow compiler instructions in debugging before asking for help – Rohit Vipin Mathews Mar 06 '12 at 10:59
  • One extra comment before your question gets down-voted into oblivion: This is C++, so lose the surplus "struct" keywords. You need "struct" to declare the structure, but after that refer to it as `node`, `node*`, `node**` rather than `struct node*`, `struct node**` – RobH Mar 06 '12 at 11:01

2 Answers2

5

Remove the ; from #define nbucket 5; and the other defines.

At the moment, line 22 is expanded by the preprocessor to become the obviously-invalid:

buckets = (struct node **)malloc(sizeof(struct node*) * 5;);
//                                                      ^^
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Henrik
  • 23,186
  • 6
  • 42
  • 92
0

The #define lines are not part of the compiler, it's part of a pre processor that runs before the compiler. The lines handled by the pre-processor should not be terminated with semicolon.

Take for example this line:

#define narray 8;// array size;

This creates a macro named narray. When the pre-processor runs it replaces all instances of narray with the replacement text, in this case 8;. As you can see, having 8; inside an expression will add a semicolon where there shouldn't be any.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621