Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Homework HelpRSS Feeds

Program of address calculation sort

Posted By: Easy Tutor     Category: C++ Programming     Views: 3594

Write a Program of address calculation sort.

Code for Program of address calculation sort in C++ Programming

//Address Calculation sort

#include<iostream.h>
#include<stdio.h>
#include<conio.h>

class add_calc{
    struct link{
        int num;
        link *next;
    }*head;
    link *hash_table[20];
public :
    add_calc();
    void getdata();
    int process(int);
    void display();
};

add_calc :: add_calc(){
    for(int i=0;i<20;i++)
    {
        hash_table[i]->num=i;
        hash_table[i]->next=NULL;
    }
}

void add_calc :: getdata()
{
    int info,rendom;
    link *n1,*p,*s;
    char ans;
    do
    {
        cout<<endl<<"Enter the info (1 to 100):";
        cin>>info;
        if(info<1 || info>100)
        {
            cout<<endl<<"Not possible:";
            break;
        }
        else
        {
            n1 = new link;
            n1->num=info;
            n1->next=NULL;
            rendom=process(info);
            if(hash_table[rendom]->next==NULL)
                hash_table[rendom]->next=n1;
            else
            {
                p=hash_table[rendom];
                s=p->next;
                while(s!=NULL && s->num < info)
                {
                    p=s;
                    s=s->next;
                }
                if(s==NULL)
                {
                    p->next=n1;
                }
                else
                {
                    p->next=n1;
                    n1->next=s;
                }
            }
          }
          cout<<endl<<"do u want to continue[y/n]:";
          fflush(stdin);
          cin>>ans;
    }while(ans!='n');
    int i=0;
    while(hash_table[i]->next==NULL && i<20)
    {
        i=i+1;
    }
    head = hash_table[i]->next;
    int j=i+1;
    while(j<20)
    {
        if(hash_table[j]->next!=NULL)
        {
            p=hash_table[i]->next;
            while(p->next!=NULL)
                p=p->next;
            p->next=hash_table[j]->next;
            i=j;
            j=j+1;
        }
        else
            j++;
    }
}

void add_calc :: display()
{
    link *temp=head;
    while(temp!=NULL)
    {
        cout<<endl<<temp->num;
        temp=temp->next;
    }
    cout<<endl<<temp->num;
}

int add_calc :: process(int info)
{
    int i=0;
    int t=info/10;
    for(i=0;i<=t;i++)
    {
        if(i==0&&i==t)
            return(i);
        elseif(i==t)
            return(i);
    }
}

void main(){
    add_calc a;
    clrscr();
    a.getdata();
    a.display();
    getch();
}
  
Share: 


Didn't find what you were looking for? Find more on Program of address calculation sort Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Program of address calculation sort is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!