// goto flag; i++; } } void main()

// this
programs are run in turbu C++

// Bucket
sort

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

#include

#include

struct Node

{

               int
value;

               struct
Node* next;

};

 struct Bucket

{

                              struct Node *head; 

};

 struct BucketList

{

               int V;

               struct
Bucket * array;

};

 struct Node*
newNode(int value)

{

               struct
Node* newnode = new Node;

               newnode->value
= value;

               newnode->next
= NULL;

               return
newnode;

}

 struct BucketList*
createBucket(int V)

{

               int i;

               struct
BucketList* bl = new BucketList;

               bl->V = V;

               bl->array
= new BucketV;  

               for(i = 0; i < V; i++)                               bl->arrayi.head
= NULL;

               return bl;

}

 void addNode(struct
BucketList* bl, int bckt, int value)

{              struct
Node *newnode = newNode(value);

               struct
Node *temp = new Node;

               if(bl->arraybckt.head !=
NULL)

               {

                              temp
= bl->arraybckt.head;

                              if(temp->value
> newnode->value)

                              {

                                             newnode->next
= bl->arraybckt.head;

                                             bl->arraybckt.head
= newnode;

                              }

                              else

                              {

                                             while(temp->next
!= NULL)

                                             {

                                                            if((temp->next)->value
> newnode->value)

                                                                           break;

                                                            temp
= temp->next;

                                             }

                                             newnode->next
= temp->next;

                                             temp->next
= newnode;

                              }

               }

               else

               {

                              bl->arraybckt.head
= newnode;

               }

}

 void
printBuckets(struct BucketList *bl)

{              int v;

               struct
Node* pCrawl = new Node;

               for(v = 0; v < bl->V; v++)

               {

                              pCrawl
= bl->arrayv.head;

                              while
(pCrawl != NULL)

                              {

                                             cout<<"->“<< pCrawl->value;

                                             pCrawl
= pCrawl->next;

                              }

               }

}

 

 

void main()

{        clrscr();

               int V =
10, range, NOE, i;

               struct
BucketList* mybucket = createBucket(V);

               cout<<" Enter the upper limit in the power of 10 (10 or 100 or 1000 ..) to create Bucket: ";                cin>>range;

               range = range/10;

               cout<<" Enter the number of data element to be sorted: ";                cin>>NOE;

               int
arr10;

               for(i = 0; i < NOE; i++)                {                               cout<<"Enter element "<>arri;

                              addNode(mybucket,
arri/range, arri);

               }

               cout<<" Sorted Data ";                printBuckets(mybucket); getch();  }     //counting sort   #include

#include

 

 

 

 

void Counterftn(int a, int n, int r, int lower)

{

               int i, j
= 0, counter10 = {0};

              

               for(i=0;
i 0)

                              goto
flag;

 

                              i++;

               }

}

 

void main()

{

clrscr();

int n, i, r, ul, ll;

cout<<"Enter the no. of data to be sorted: "<>n;

 

cout<<"Enter the lower limit: "<>ll;

cout<<"enter uper limit"<>ul;

 

              

r = ul-ll+1;

 

int arr10;

               for(i =
0; i < n; i++)                {                               cout<<"Enter element "<>arri;

               }

 

Counterftn(arr, n, r, ll);

 

              

cout<<"Sorted Data "<“<

#include

 

 

 

int getMax(int arr, int x)

{

               int
m_val = arr0;

               for (int
i = 1; i < x; i++)                               if (arri > m_val)

                                             m_val
= arri;

               return
m_val;

}

 

 

void countSort(int arr, int x, int exp)

{

              

               int
output10;

               int u;

               int
count10 = {0};

 

              

               for (u =
0; u < x; u++)                               count(arru / exp) % 10++;                                 for (u = 1; u < 10; u++)                               countu += countu-1;                                 for (u = x - 1; u >= 0; u–)

               {

                      outputcount(arru / exp) % 10 – 1 =
arru;

                              count(arru
/ exp) % 10–;

               }

 

              

               for (u =
0; u < x; u++)                               arru = outputu; }     void radixftn(int arr, int n) {                int exp, m;                m = getMax(arr, n);                                 for (exp = 1; m/exp > 0; exp *= 10)

                              countSort(arr,
n, exp);

}

 

void main()

{

clrscr();

               int n,
j;

               cout<<"Enter the number of data to be sorted: "<>n;

 

               int
arr10;

               for(j =
0; j < n; j++)                {                               cout<<"Enter element "<>arrj;

               }

 

               radixftn(arr,
n);

 

              

               cout<<"Sorted Data "<“<

x

Hi!
I'm Isaac!

Would you like to get a custom essay? How about receiving a customized one?

Check it out