i have to sort an array of integers using bucket sort.
i kind of made it but there is still a problem.
before i make the sort i have to verify if there is one or many numbers which begins with one or many zeros.if there are this kind of numbers the program should suffer some modifications to rule properly.i think that i have to eliminate those zeros but at the end(when i have to list the array,the elements should appear as they were read-with zeros)
can anyoane help me????
this is the code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct nod 
{
  char *cuv;
  nod* adr;
}; 
int main()
{
 nod* cap[30];
 nod* cap2[50];
 nod* q;
 int i,n,b,k,j,m,p,l;
 char *v[30];
 printf("introduceti baza in care urmeaza sa fie introduse numerele(maxim 30):");
 scanf("%d",&b);
 printf("introduceti numarul de elemente:");
 scanf("%d",&n);   
 for (i=0;i<n;i++)
 {
  printf("v[%d]=",i);
  v[i]=(char*)malloc(50*sizeof(char)); 
  scanf("%s",v[i]);    
 }
 for (k=0;k<50;k++)
          cap2[k]=0;
 for (i=0;i<n;i++)
 {
  q=(nod*)malloc(sizeof(nod));
  m=strlen(v[i]);//m e int
  q->cuv=v[i];
  q->adr=cap2[m];
  cap2[m]=q ;   
 }
 for (l=0;l<50;l++)
 {
  for (i=l-1;i>=0;i--)
      {
      for (k=0;k<30;k++)
          cap[k]=0;
         while (cap2[l])
            {
            q=(nod*)malloc(sizeof(nod));
            m=cap2[l]->cuv[i]-48;//m e int
            q->cuv=cap2[l]->cuv;
            q->adr=cap[m];
            cap[m]=q ;  
            cap2[l]=cap2[l]->adr;  
            } 
        
        for (k=29;k>=0;k--)
             {
              while (cap[k])
                    {
                    q=(nod*)malloc(sizeof(nod));
                    q->cuv=cap[k]->cuv;
                    q->adr=cap2[l];
                    cap2[l]=q;   
                    cap[k]=cap[k]->adr;
                    }            
        }   
      } 
   }
  p=0;
  for (l=0;l<50;l++)
  {
  while (cap2[l])
        {
         v[p]=cap2[l]->cuv;
         cap2[l]=cap2[l]->adr;
         p++;        
        }    
  }
 for (i=0;i<n;i++)
      printf("%s\n",v[i]);
 system("pause");
 return 0;   
}

Edited 7 Years Ago by WaltP: Added CODE tags -- with all the help about them, how could you miss using them????

i forgot to mention that the program should work for number in any numeration base from 2 to 30
:(

This article has been dead for over six months. Start a new discussion instead.