![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2006
Posts: 4
Rep Power: 0
![]() |
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);
} |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 816
Rep Power: 4
![]() |
You might want to let us know what the error is, we are not all mind-readers.
One thing that will cause a problem is this line near the top of create head->next=p1; Note: I didn't look any further, there may be more problems, you need to give more information. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: May 2006
Posts: 4
Rep Power: 0
![]() |
thank you Dark.
This is what I want to know. I really didn't know where the error occured.But I have no more info about it. ![]() |
|
|
|
|
|
#4 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 816
Rep Power: 4
![]() |
You might not know where the error occurred, but you must know what sort of error it was. For example:
- Did the program not compile? (show the error messages) - Did the program not link? (show the error messages) - Did the program run but not produce the expected output? (show the output) - Did the program run for a bit and then stop? (show any output or error) - Did the program stop straight away? (show any error messages) - Did the program connect to the net and buy stuff on ebay using your credit card? (show me what it bought, I might want some too). |
|
|
|
|
|
#5 |
|
Newbie
Join Date: May 2006
Posts: 4
Rep Power: 0
![]() |
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);
} |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|