Programming is Passion,Software Development is an Adventure- Willy David Jr

Programming is Passion,Software Development is an Adventure- Willy David Jr

Radix Sort

My post today was all about my final project in Data Structure and Algorithm. I already took Data Structure wayback when I was in Computer Engineering Technology. And I never thought that I will take this again because I expect more a lot on project development and system design. So I just want to share my final project but I will not include Binary Search because that algorithm was also included in my project. I edit the program to make it simple and remove graphics. What is so good with this program is that it has an iteration that was discussed on my Numerical Analysis class. I wonder how can I apply more my Mathematics skills on my developer's track. Smile

#include<stdio.h>
#include<math.h>
#define MAX 13            /* Initialize 13 numbers so that we can see that the program was actually sorting*/
#define PTR_SIZE 10


typedef struct _node_var
{
  int data;
  struct _node_var *next;
}node_var;

void initialise ( node_var* [] );
void radix_sort ( int [], node_var* [] );
void refill_list ( int [], node_var* []);
void insert2q ( node_var* [], int, int);
void     show ( int [] );

 int del_q ( node_var* [] , int );

void main()
{
  int list[13];
  int ctd;
  node_var *aux[PTR_SIZE];
  clrscr();
  initialise ( aux );
  printf("Randomized list is :\n");
  for (ctd=0;ctd<13;ctd++)
  {
   scanf ("%d",&list[ctd]);
  }

  show(list);

  radix_sort ( list , aux );
  printf("\n\nSorted list is :\n");
  show(list);

}

void initialise ( node_var *aux[] )
{
  int i;
  for(i=0;i<PTR_SIZE;i++)
  auxIdea = NULL;
}


void radix_sort ( int list[], node_var *aux[] )
{
  int i, exp=0, j, max, nod =0,nth_d ;

  /* FIND LARGEST NUMBER IN ARRAY */
  max = list[0];
  for(i=0;i<MAX;i++)
  if(listIdea > max )
  max = listIdea;

  /* FIND NO. DIGITS IN MAX */

  while(max > 0 )
  {
   nod++;
   max = max / 10;
  }

  for( i=0; i<nod; i++)
  {
      exp++;
      for(j=0;j<MAX;j++)
      {

   nth_d =  list[j] % (int)pow(10,exp);
   nth_d = nth_d / (int)pow(10,exp-1);
   insert2q( aux, nth_d , list[j] );
      }

      refill_list (list,aux);
      printf("\n\nIteration %d :\n\t ",i+1);         /*Includes iteration that was discussed on my Numerical Analysis Class*/Smile
      show(list);

  }
}

void insert2q ( node_var *aux[] ,int i, int val )
{
   node_var *temp,*rear;
   temp = ( node_var * ) malloc ( sizeof (node_var) );
   temp->data = val;
   temp->next = NULL;

   if(auxIdea==NULL)
   {
    auxIdea = temp;
    rear = temp;
   }
   else
   { rear = auxIdea;
     while(rear->next != NULL )
     rear = rear->next;

     rear->next = temp;
     rear = temp;
   }
}

void refill_list ( int list[] , node_var *aux[] )
{
     int i, j=0;

     for(i=0;i<PTR_SIZE;i++)
     {
 while(auxIdea != NULL)
 {
  list[j] = del_q ( aux , i );
  j++;
 }
     }
}

int del_q ( node_var *aux[] , int i )
{
  node_var *temp;

  temp = auxIdea;
  auxIdea = auxIdea->next;
  temp->next = NULL;
  return temp->data;
}

void show ( int list[] )
{
  int i;
  for(i=0;i<MAX;i++)
  printf("%8d",listIdea);
}

 

That's it! Well before I forgot, the blog seems to change my "[  i  ]" array as a bulb symbol.

 

Comments

keithrull said:

try using the developer toolbar so taht you could put syntax highlighting to your code. it can be found on your devpinoy profile. I think that would also eliminate the Idea problem.

nice post :)

# October 9, 2006 1:53 PM

dehran ph said:

better if you can give us at least little i idea what is radix sort, sequential, selection, heap, bubble sort lng kasi alam namin. ;)

# October 9, 2006 8:16 PM

lamia said:

Now that light bulb thing is making me laugh!!! Lolz!

# October 9, 2006 11:10 PM

Orange said:

That light bulb is an accidental representation of an array was it a Music?

Nakakalito.

# October 10, 2006 2:24 AM