the inputs are these

computer 21
sabanci 4
sabanci 6
university 6
university 12
computer 17
university 3
computer 9
computer 6
sabanci 2
university 9

problem occurs at third line when the input name1 is equal with the previous input name1.

Really thx for helping. Sorry for mess.

#include <fstream>
#include <string>
#include <iostream>


using namespace std;


class linklist
{
public:

    linklist();

    void InsertOrdered(string name, string key);
    // void PrintList();

    ~linklist();

private:

    struct sublink
    {
    string key;
    sublink *next;

       sublink()
       {
        next = NULL;
        key = "";
       }
       };

    struct link
    {
    string name;
    sublink *subnext;
    link *mainnext;

       link()
       {
        mainnext = NULL;
        name = "";
       }


    };
   link *head;
};



linklist::linklist()

{
    head = new link;    // for dummy
    head->mainnext = NULL;
    head->subnext = NULL;
}


/*void linklist::PrintList()
{



} */

void linklist::InsertOrdered(string name, string key)
{


    link *tracker,*tracker2,*inserter;
    sublink *s_tracker,*s_tracker2,*s_insert;


    tracker = head ;
    tracker2 =  head;

    if(head->mainnext==NULL)
    {

        inserter = new link;
        s_insert = new sublink;


        head->mainnext = inserter;
        inserter->name = name;

        inserter->subnext = s_insert;

        s_insert->key = key;

    }
    else if(name<(tracker->mainnext->name))
    {
        inserter = new link;
        s_insert = new sublink;


        inserter->mainnext = head->mainnext;
        head->mainnext = inserter;
        inserter->name = name;
        inserter->subnext = s_insert;
        s_insert->key = key;
    }
    else
    {

        while(tracker->mainnext!=NULL)
        {
            if(tracker->name <= name)

            {
                tracker2 = tracker;
                tracker = tracker->mainnext;

            }
        }
        if(tracker->name==name)
        {
            if( tracker->subnext == NULL)
            {
                s_insert = new sublink;

                tracker->subnext = s_insert;

                s_insert->key = key ;
            }
            else if(key < (tracker->subnext->key))
            {
                s_insert = new sublink;

                s_insert->next = tracker->subnext;
                tracker->subnext = s_insert;
                s_insert->key = key;
            }
            else
            {

                s_tracker = tracker->subnext;


                while(s_tracker->key <= key) 
                {
                    s_tracker2 = s_tracker;
                    s_tracker = s_tracker->next;
                }

                              else if(s_tracker->key < key)
                {
                    s_insert = new sublink;

                    s_insert->next=s_tracker->next;
                    s_tracker2->next = s_insert;

                    s_insert->key = key;

                }
                else if(s_tracker->next==NULL)
                {
                    s_insert = new sublink;

                    s_tracker->next = s_insert;

                    s_insert->key = key ;
                }
                else
                    ;
            }

        }
        else if(tracker->mainnext == NULL)
        {
            inserter = new link;

            s_insert = new sublink;

            tracker->mainnext = inserter;

            inserter->name = name;

            inserter->subnext = s_insert;

            s_insert->key = key;

        }
        else
        {

            inserter = new link;

            s_insert = new sublink;

            inserter->mainnext = tracker;

            tracker2->mainnext = inserter;

            inserter->name = name;

            inserter->subnext = s_insert;

            s_insert->key = key;

        }

     }
}

linklist::~linklist()
{
    delete head;

}
 int main()
{
    linklist a;

    string name1,key1;

    ifstream myfile;
    myfile.open("docdb.txt");



    while(!myfile.eof())
    {

    myfile >> name1 >> key1;
    a.InsertOrdered(name1, key1);


       }
}

the inputs are these

1) use code tags. /* code goes here */
2) Whats your problem. We aren't compilers. We don't just compiler the
code in our head and find errors, although we might be able to.
3) for( int n = 0; n!= 100; n++) re_read_Steps1And2();
4) Fix those things and post back neater and clearer question.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.