typedef struct node{ int x;struct *next;}LNode,*LinkList; LNode *p;LinkList q;请问p,q的区别??

如题所述

struct node{ int x;struct *next;} //定义了一个结构体
typedef 的意思是用后面的名字代替struct node{ int x;struct *next;}
意思就是LNode代表了你定义的结构体
后面还定义了结构体指针,*LinkList
LNode *p 为定义了一个指向结构体的指针p
LinkList q,这句话的意思还是定义了一个结构体二级指针
所以整体来说 p 和 q基本无区别
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-09-26
#include <stdio.h>
typedef struct student
{
int id;
char name[20];
float score;
}elemtype;
elemtype stu[ ]=,,};
typedef struct list_type
{
elemtype data[3];
int num;
}listtype;

int insert1 (listtype *l,int i,elemtype x);

int main()
{
int i;
listtype lt;
lt.num = 0;

for (i=0;i<3;i++)
{
printf("%d,%s,%f",stu[i].id,stu[i].name,stu[i].score);
}
insert1(<, 0, stu[2]);
insert1(<, 1, stu[1]);
insert1(<, 2, stu[0]);
printf("\nresult:\n");
for (i = 0; i < lt.num; i++)
{
printf("%d, %s, %f\n", lt.data[i].id, lt.data[i].name, lt.data[i].score);
}
return 0;
}

# define true 0
# define false 1
int insert1 (listtype *l,int i,elemtype x)
{
int j;
if (l->num>=3)
{
printf("the list is full,can not insert.");
return(false);
}
if ((i<0)||(i>l->num))
{
printf("i is invalid value");
return(false);
}
for (j=l->num-1;j>=i;j--)
l->data[j+1]=l->data[j];
l->data[i]=x;
l->num++;
return(true);
}
第2个回答  2011-09-25
首先要清楚typedef的用法“struct node{ int x;struct *next;}”这其实是一个匿名类型,“typedef struct node{ int x;struct *next;}LNode,*LinkList;”这句话其实就是定义一个就个体类型LNode,和一个结构体指针类型*LinkList。所以p,q都是给结构体指针类型。
第3个回答  2011-09-25
无区别
第4个回答  2011-09-26
无区别
相似回答