View Single Post
Old May 25th, 2006, 12:40 AM   #5
Pacer
Newbie
 
Join Date: May 2006
Posts: 4
Rep Power: 0 Pacer is on a distinguished road
Dark,I have completed.
/* linked list main file */
#include "H1.h"

linklist * create(linklist * point[2])   /* Define the Function to create linked list*/
{
        linklist * head,* tail;
        linklist * p1,* p2;
        int flag=0;
        int count=2;
        //linklist * point[2]; /* Deposit head and tail */
        p1=p2=(linklist *)malloc(LEN);
        printf("\nMember[1] :");
        scanf("%c",&p1->data);
        head=NULL;
        
        while(p1->data!='0')
        {
                flag++;
                if(flag==1)           /* the first node*/
                {
                        head=p1;
                        p1->pre=p1->next=NULL;
                }
                else                  /* other nodes except the first one */
                {
                        p2->next=p1;
                        p1->pre=p2;
                }
                p2=p1;
                p1=(linklist *)malloc(LEN);
                printf("Member[%d] :\n",count++);
                scanf("%c",&p1->data);
        }                         /* create nodes */

        p2->next=NULL;
        tail=p2;
        point[0]=head;
        point[1]=tail;
        return * point;
}
/////////////////////////////////////////////////
void dispAhead(linklist * head) /* Define the function to display linked list */
{
        linklist * tem;
        int j=1;
        if((tem=head)!=NULL)
        {
                printf("\n");
                while(tem)
                {
                        printf("Member[%d] :",j++);
                        printf("%c",tem->data);
                        tem=tem->next;
                }
        }
        else
        {
                printf("head node error, exit now!\n");
                exit(0);
        } 
}

//////////////////////////////////////////////////
void main()
{
        linklist * point[2];
        linklist * tem;
    tem=create(point);
        dispAhead(tem);

}
Pacer is offline   Reply With Quote