Problem of understanding recursion

This is a discussion on Problem of understanding recursion within the C Programming forums, part of the General Programming Boards category; Hello. Need despereately help with this simple program.Tried to compile it with bcc32 and VC++ 6 but none of them ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    2

    Problem of understanding recursion

    Hello. Need despereately help with this simple program.Tried to compile it with bcc32 and VC++ 6 but none of them gives me the .exe file.Doesnt recognize the Quicksort function.It says that has no prototype in function main and in function Quicksort itself.Please can somebody tell me where is the mistake?
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <dos.h>                                             
    #include <sys\timeb.h> 
    
    #define Arraysize  10
    
    
    
    void QuickSort (int a[Arraysize],long int left, long int right);
    
    
    int main(void)
    {
    int t;
    int B[Arraysize];
    srand(time(NULL));
    for (t=0; t<Arraysize; t++) {
    B[t] = rand () * Arraysize / (RAND_MAX + 1);
    printf("seed is %d\n r.number is %d\t\t",B[t]);
    }
    printf("Start partition\n");
    Quicksort(B,0,Arraysize);
    for (t=0; t<Arraysize; t++) {
    printf("array coming");
    printf(" %d\t\t", B[t]);
    }
    return 0;
    }
    
    void QuickSort (int a[Arraysize],long int left, long int right)
    {
    long int i,j,x,h;
    
    i=left; j=right;
    srand(time(NULL));
    x=a[rand() * Arraysize / (RAND_MAX +1)];
    
    while (i<=j) 
    {
    
    while (a[i]<x) { 
    i++;}
    
    while (a[j]>x) {
     j--;}
    
    if (i<=j) {
    h=a[i];
    a[i]=a[j];
    a[j]=h;}
    
    }
    if (left<j) { 
     Quicksort (a,left, j);}         
    
    if (i<right) {
    Quicksort (a,i,right);}       
    return;
    }

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    You're calling Quicksort in your code, not QuickSort.

    Also, only seed the random number generator at the start of the program.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    2

    Thanks

    ) Damn I was looking for the mistake everywhere and I never spotted it. ) Thanks a lot again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. a simple recursion question
    By tetra in forum C++ Programming
    Replies: 6
    Last Post: 10-27-2002, 09:56 AM
  5. recursion problem
    By dustinc in forum C++ Programming
    Replies: 1
    Last Post: 10-29-2001, 03:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21