Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old May 24th, 2006, 10:33 PM   #1
Pacer
Newbie
 
Join Date: May 2006
Posts: 4
Rep Power: 0 Pacer is on a distinguished road
error of double linked list .

Hello,everybody.
I have no idea to rectify my error.
Could everyone helps me to solve it,thanks all.
I am a fresh man.Thanks again.

head file:
/* head file for double linked list */
/* Filename H1.h */

#include <stdio.h>
#include <stdlib.h>
#define LEN sizeof(linklist) /* Define the length of linked list */

typedef struct link
{
        char data;
        struct link * pre;
        struct link * next;
}linklist;            /* Defint structure of linked list */

main file:
/* double linked list main file */
/* Filename double.cpp */
#include "H1.h"

linklist * create(void)   /* Define the Function to create linked list*/
{
        linklist * head=NULL;
        linklist * p1,* p2;
        int i=2;              /* Define the sequence number */
        p1=(linklist *)malloc(LEN);
        head->next=p1;
        p1->pre=head;
        printf("Member[1] :");
        scanf("%c",&p1->data);
        
        if(p1!=NULL)
        {
                do
                {
                        p2=(linklist *)malloc(LEN);
                        printf("Member[%d] :",i);
                        scanf("%c",&p2->data);
                        p2->pre=p1;
                        p1->next=p2;
                        p1=p2;
                }while(p1->data!='$');
                p1->next=NULL;
                return head;
        }
}
/////////////////////////////////////////////////
void display(linklist * head) /* Define the function to display linked list */
{
        linklist * tem;
        int j=1;
        if((tem=head->next)!=NULL)
        {
                printf("\n");
                while(tem)
                {
                        printf("Member[%d] :",j++);
                        printf("%c",tem->data);
                }
        }
        else
        {
                printf("head node error, exit now!\n");
                exit(0);
        } 
}

//////////////////////////////////////////////////
void main()
{
        linklist * test_head;
        test_head=create();
        display(test_head);
}
Pacer is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:42 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC