GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Feb-2005, 21:18
ap6118 ap6118 is offline
Junior Member
 
Join Date: Feb 2005
Posts: 62
ap6118 is on a distinguished road
Question

bucket sort problem


i needed to write a function that takes an integer array and the array size as arguments and performs as follows:
a)place each value of the single-subscripted array into a row of the bucket array based on the value's ones digit.for exemple 97 is placed in row 7,3 is placed in row 3 and 100 is placed in row 0.
b)loop through the bucket array row by row,and copy the values back to the original array.
c)repeat the process for each subsequentdigit position( tens,hundreds,thousands...)

i have been given that as a starter in c ++ programming and even though my template was correct,i feel it is not the most efficient way.
  #2  
Old 24-Feb-2005, 00:58
ap6118 ap6118 is offline
Junior Member
 
Join Date: Feb 2005
Posts: 62
ap6118 is on a distinguished road
Lightbulb

eureka


i figured it out.and i thought that i should post it in case someone needs it in the future.

CPP / C++ / C Code:
void bucketSort(int a;int size)
{
   int b[10][size-1];
   int digit =1;
     for (int j = 0;j<size;++j)
	    int k=(a[j]%(10*digit)-a[j]%digit)/digit;
           b[k][k++]=a[j];
	int m=0;
	for (j=0;j<size;j++)
	   {
	  for (k=0;k<b[][k];k++)
	      a[m++]=b[j][k];
		   
		   }

		   for (k=0;k<size;k++)
		       b[][k]=0;
			   digit*=10;
			   }//end of the function
  #3  
Old 15-Apr-2005, 13:17
glulu76 glulu76 is offline
New Member
 
Join Date: Apr 2005
Posts: 22
glulu76 is on a distinguished road

Ok this is what I have so far but I keep getting errors.


I keep trying different ways to get this bucket sort but I don't have much to go on because their is nothing on bucket sorts in my book. I have used search engines to try to find out about them. They show me some code about them but nothing on how they work in arrays. I am just getting more confused.

CPP / C++ / C Code:
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include <algorithm>



void bucketSort(int a;int size)

{
   int b[10][size-1];
   int digit =1;
     for (int j = 0;j<size;++j)
      int k=(a[j]%(10*digit)-a[j]%digit)/digit;
           b[k][k++]=a[j];
  int m=0;
  for (j=0;j<size;j++)
     {
    for (k=0;k<b[][k];k++)
        a[m++]=b[j][k];
       
       }

       for (k=0;k<size;k++)
           b[][k]=0;
         digit*=10;
}//end of the function
int main ()

{


  const int MAXELS = 20;


    int code,z;
    int id[MAXELS]={0};

  srand(time(NULL));
  z=0;
  while(z<20)
 

  {
   code = 1.0 + (double)rand()/(double)(RAND_MAX + 1) * 99.00;
    
    if (size == z)
      cout << "This is a duplicate number " <<code<< "\n";
    else
    {
      
      cout <<"\nThe code is: " <<code<<"\n";
      
      z++;
    
    }
  }
  
  return 0;
}

  #4  
Old 15-Apr-2005, 19:02
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
How many different threads do we have to heep track of for this problem? Stick to one thread! You know it's your when your name is under the title.
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge sort on a linked list Temujin_12 C++ Forum 1 06-Mar-2008 21:33
[GIM] gim.h dsmith C Programming Language 0 18-Jan-2005 09:48
Another FX 5600 problem (but with details that might shed light on this) BobDaDuck Computer Hardware Forum 2 16-Apr-2004 08:53
problem with php5 cgi installation fab13 Apache Web Server Forum 3 19-Nov-2003 10:11
join problem zuzupus MySQL / PHP Forum 0 14-Aug-2003 06:11

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:53.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.