radix sort using stack

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tejas2991
    New Member
    • Feb 2009
    • 7

    radix sort using stack

    could someone please gimme the main code for "radix sort" using stack
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Originally posted by tejas2991
    could someone please gimme the main code for "radix sort" using stack
    I think the best place to start is for you [the OP, not other respondents] to refresh our memory and describe the distinctive features of a "radix sort".

    Comment

    • Tired
      New Member
      • Feb 2009
      • 13

      #3
      try and paste the code tejas and put in the errors or your problems at the end.

      Comment

      • tejas2991
        New Member
        • Feb 2009
        • 7

        #4
        well the thing is i want the main coding and then on that basis i could develop the rest of the code.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by tejas2991
          well the thing is i want the main coding and then on that basis i could develop the rest of the code.
          The main algorithm can be found anywhere on the net; this is one hit.

          kind regards,

          Jos

          Comment

          • tejas2991
            New Member
            • Feb 2009
            • 7

            #6
            #include<stdio. h>
            #include<conio. h>
            #include<stdlib .h>
            struct stack
            {
            int s[10];
            int top=0;
            int max=9;
            }
            push(stack x,int y)
            {
            stack s2=x;
            int data= y;
            for(int t=s2.top;t>=0;t--)
            {
            printf("enter value in s2[%d]=",t);
            scanf("%d",&s2[t]);
            }
            }
            void radixsort(s2,in t n)
            {
            int rear[10],front[10],first,p,q,i,k, exp,y,j;

            Comment

            • tejas2991
              New Member
              • Feb 2009
              • 7

              #7
              */ radix sort/*



              #define NUMELTS 100
              # include<stdio.h >
              #include<conio. h>
              #include<math.h >
              void radixsort(int a[],int);
              void main()
              {
              int n,a[20],i;
              clrscr();
              printf("
              enter the number :");
              scanf("%d",&n);
              printf("
              ENTER THE DATA -
              ");
              for(i=0;i<n;i++ )
              {
              printf("%d. ",i+1);
              scanf("%d",&a[i]);
              }
              radixsort(a,n);
              getch();
              }
              void radixsort(int a[],int n)
              {
              int rear[10],front[10],first,p,q,exp, k,i,y,j;
              struct
              {
              int info;
              int next;
              }node[NUMELTS];
              for(i=0;i<n-1;i++)
              {
              node[i].info=a[i];
              node[i].next=i+1;
              }
              node[n-1].info=a[n-1];
              node[n-1].next=-1;
              first=0;
              for(k=1;k<=2;k+ +) //consider only 2 digit number
              {
              for(i=0;i<10;i+ +)
              {
              front[i]=-1;
              rear[i]=-1;
              }
              while(first!=-1)
              {
              p=first;
              first=node[first].next;
              y=node[p].info;
              exp=pow(10,k-1);
              j=(y/exp)%10;
              q=rear[j];
              if(q==-1)
              front[j]=p;
              else
              node[q].next=p;
              rear[j]=p;
              }
              for(j=0;j<10&&f ront[j]==-1;j++)
              ;
              first=front[j];
              while(j<=9)
              {
              for(i=j+1;i<10& &front[i]==-1;i++)
              ;
              if(i<=9)
              {
              p=i;
              node[rear[j]].next=front[i];
              }
              j=i;
              }
              node[rear[p]].next=-1;
              }
              //copy into original array
              for(i=0;i<n;i++ )
              {
              a[i]=node[first].info;
              first=node[first].next;
              }
              clrscr();
              textcolor(YELLO W);
              cprintf("
              DATA AFTER SORTING:
              ");
              for(i=0;i<n;i++ )
              printf("
              %d . %d",i+1,a[i]);
              }
              i m unable to club this program in stacks the one i have created i.e mentioned above...plzzz help..!!

              Comment

              • donbock
                Recognized Expert Top Contributor
                • Mar 2008
                • 2427

                #8
                Originally posted by tejas2991
                i m unable to club this program in stacks the one i have created i.e mentioned above...plzzz help..!!
                OK ... what goes wrong? Do you get a compiler error? Do you get a run-time error? Does your program give the wrong answer? I need a clue.

                By the way, it would be easier to examine your source code if you wrapped it in CODE tags.

                Comment

                • tejas2991
                  New Member
                  • Feb 2009
                  • 7

                  #9
                  no no...the radix sort program works properly..
                  so inorder to store the data in stacks...i need to change the for loops according to the stack..that is what i m unable to do...

                  Comment

                  Working...