Thread: Linked list, just small problem remained

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    11

    Help me, Friends and Gurus ????

    Hi; Friends;
    I solved most of the work. But it's now having problem to insert in the middle.
    Any can suggest me where to correct, how to correct, and where I did mistake.
    Here is my that insertnode function:

    ....Code ..........
    struct node *head = (struct node *) NULL;
    struct node *end = struct node *) NULL;
    ......
    void insertnode(struct node *insert)
    {
    struct node *curr, *prev;
    if(head == NULL)
    {
    head = insert;
    insert->next=head;
    end=insert;
    }
    else if(head==end)
    {
    if(strcmp(head->name,insert->name) < 0)
    {
    insert->next=head;
    head->next=insert;
    end=insert;
    }
    else {
    head=insert;
    insert->next=end;
    end->next=head;
    }
    }
    /* inserting in the middle part is here....*/
    /*...........Problem here ............*/
    /* .........segmentation error....... */

    else{
    curr = head;
    while(strcmp(curr->name,insert->name) < 0) {
    curr = curr->next;
    if(curr==head)
    break;
    }
    if(curr=head){
    insert->next=head;
    head=insert;
    }
    else{
    prev=head;
    while(prev->next!=curr){
    prev=prev->next;
    }
    prev->next=insert;
    insert->next=curr;
    if(end==prev)
    end=insert;
    }
    }
    }
    Last edited by yescha; 12-02-2001 at 08:23 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List Not Saving Value as Int
    By bar338 in forum C Programming
    Replies: 4
    Last Post: 05-04-2009, 07:53 PM
  2. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 10:03 AM
  3. Linked List Problem
    By Syneris in forum C++ Programming
    Replies: 4
    Last Post: 01-07-2006, 12:03 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM