473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

radix sort using stack

could someone please gimme the main code for "radix sort" using stack
Feb 27 '09 #1
8 6800
donbock
2,426 Expert 2GB
@tejas2991
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".
Feb 27 '09 #2
Tired
13
try and paste the code tejas and put in the errors or your problems at the end.
Feb 28 '09 #3
well the thing is i want the main coding and then on that basis i could develop the rest of the code.
Mar 1 '09 #4
JosAH
11,448 Expert 8TB
@tejas2991
The main algorithm can be found anywhere on the net; this is one hit.

kind regards,

Jos
Mar 1 '09 #5
#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,int n)
{
int rear[10],front[10],first,p,q,i,k,exp,y,j;
Mar 4 '09 #6
*/ 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&&front[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(YELLOW);
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..!!
Mar 4 '09 #7
donbock
2,426 Expert 2GB
@tejas2991
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.
Mar 4 '09 #8
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...
Mar 5 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Kevin Doyle | last post by:
Hi I just found this macro. I want to convert a dword to string using this _ultoa but I don't understand the radix part of the function. what value of radix should I use so as not to effect the...
12
by: Eva | last post by:
Hi, I try to implement quick sort. I sort vectors by their first value. 10 2 3 4 9 3 5 6 10 4 5 6 must be 9 3 5 6 10 2 3 4 10 4 5 6 The prog works great on maybe 500 vectors, but I have an...
1
by: strotee | last post by:
#include <iostream> #include <ctime> using namespace std; // function declarations void swap(int *a, int *b); void sort(int arr, int beg, int end); int main() {
7
by: Foodbank | last post by:
Hi everyone. I'm having trouble with this radix sorting program. I've gotten some of it coded except for the actual sorting :( The book I'm teaching myself with (Data Structures Using C and...
2
by: Foodbank | last post by:
Hi everyone, I'm having trouble implementing a supposedly simple Least Significant Digit first Radix Sort. The book I'm using gave me somewhat of a template that I touched up (below), but I'm...
1
by: Foodbank | last post by:
Hi, I'm currently teaching myself C data structures in preparation for a job transition and I've just passed the point in which radix sorting was covered in my book. I've recently finished a...
3
by: Tracey | last post by:
I'm learning C++ and was stuck when writing code to convert a negative decimal number string to a hexdecimal number. For example, suppose the function interface is defined as: int atoi( const...
13
by: ralphedge | last post by:
These sorts work fine on 100000 ints but if I go much higher they will both segmentation fault **************************MERGESORT********************* mergesort(int *a, int size) //a is...
0
by: Nick Keighley | last post by:
On Oct 25, 1:50 pm, Eric Sosman <esos...@ieee-dot-org.invalidwrote: since the pointer indicates the "last" digit. It indicates how many digits there are. I'm guessing that N is just some large...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.