读书人

单链表的一道面试题,该如何处理

发布时间: 2012-02-13 17:20:26 作者: rapoo

单链表的一道面试题
typedef struct _Check_SN
{
int index;
char SN[30];
struct _Check_SN *next;
}CheckSN;
static CheckSN *HEAD,*LAST;
static CheckSN *HEAD,*LAST;
void *create(int sn_num,char *p_sn)
{
CheckSN *p_temp;
if(sn_num!=0)
{
p_temp=(CheckSN *)malloc(LEN);
p_temp-> index=sn_num;
strcpy (p_temp-> sn,p_sn);
p_temp-> next=NULL;
LAST-> next=p1;
LAST=p1;
}
else
{
HEAD=LAST=(CheckSN *)malloc(LEN);
HEAD-> index=sn_num;
strcpy (HEAD-> sn,p_sn);
HEAD-> next=NULL;
}
}

这里CREAT函数是建立个单链表,有问题么?百思不得其解,请高手赐教

[解决办法]
lz写的不象建立个链表,而象往链表中加入一个节点
else
{
HEAD=LAST=(CheckSN *)malloc(LEN);
HEAD-> index=sn_num;
strcpy (HEAD-> sn,p_sn);
HEAD-> next=NULL;
}
这段代码放这里有点不妥。。
[解决办法]
I think you should define a struct like the following codes to point the HEAD&LAST of your single chain.

struct CheckSN_list {
struct CheckSN *head;
struct CheckSN *last;
};
struct CheckSN_list Clist = {NULL, NULL};

读书人网 >C语言

热点推荐