c++ singly linked list (using structures), something's wrong with insertion
<p>I am writing a program to insert elements into singly linked list based on their strings,(function strcmp is to put them into right place).</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;cstring&gt;
using namespace std;

struct list
{
    int num;
    char* word;
    list* next;
};
list* head;
void insert(int number,char* txt){
    list* ptr,*tmp;
        ptr=head;
    list* newlist=new list;
    newlist-&gt;num=number;
    newlist-&gt;next=NULL;
    //newlist-&gt;word= new char(strlen(txt)+1);
    newlist-&gt;word=txt;
    if(head==NULL){
        head=newlist;
        newlist-&gt;next=NULL;
    }
    else while(ptr!=NULL){
            if(strcmp(txt,ptr-&gt;word)&gt;=0){
                if(ptr-&gt;next!=NULL &amp;&amp; strcmp(txt,ptr-&gt;next-&gt;word)&lt;=0)
            {
                tmp=ptr-&gt;next;
                ptr-&gt;next=newlist;
                newlist-&gt;next=tmp;
                break;
            }
                else if(ptr-&gt;next!=NULL &amp;&amp; strcmp(txt,ptr-&gt;next-&gt;word)&gt;0)
                    ptr=ptr-&gt;next;
                else
                 {
                    //next is empty
                    ptr-&gt;next=newlist;
                    break;
                 }
    }
            else{
                //txt mniejszy niz w 1szym elemencie
                newlist-&gt;next=head;
                head=newlist;
                break;
            }
            return;
    }
}

void print(){
    list *druk;
    druk=head;
    while(druk!=NULL){
        cout&lt;&lt;"txt: "&lt;&lt;druk-&gt;word&lt;&lt;" | "&lt;&lt;"num: "&lt;&lt;druk-&gt;num&lt;&lt;endl;
        druk=druk-&gt;next;
    }
    return;
}

int main(){

    head=NULL;

    insert(242,"Szulasdj"); 
    insert(32,"aab");
    insert(32,"aab");
    insert(14,"aaa");
    insert(85,"bbb");
    insert(5,"aac");
    insert(3,"ccc");
    insert(4,"cdc");
    insert(2,"ccd");

    print();
    cout &lt;&lt; endl &lt;&lt; endl;
    getchar();
    return 0;
}
</code></pre>

<p>and I cannot figure out why it doesn't print all elements I inserted. If you could tell me where my mistake lies I would really appreciate it.</p>
