首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

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

2012-02-13 
单链表的一道面试题typedefstruct_Check_SN{intindexcharSN[30]struct_Check_SN*next}CheckSNstaticCh

单链表的一道面试题
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};

热点排行