L=(LNode *)malloc(sizeof(LNode));
来源:百度知道 编辑:UC知道 时间:2024/07/01 02:24:42
//单链表的逆置
#include<stdlib.h>
#include<stdio.h>
typedef struct LNode{
int num;
struct LNode *next;
}LNode;//定义链表的节点
void creat(LNode *L)
{
int i,count;//i用来计数,count用来确定链表的长度
printf("please put in the count :\n");
scanf("%d",&count);//输入链表的长度
printf("please put in the number:\n");
for(i=0;i<count;i++)
{
LNode *p;
p=(LNode *)malloc(sizeof(LNode));
scanf("%d",&p->num);//依次输入链表的数值
p->next=L->next;
L->next=p;
L=p;
}
}//创建链表,头节点为L
void print(LNode *L)
{
while(L!=NULL)
{
printf("%d ",L->num);
L=L->next;
}
printf("\n");
}//输出链表
void reverse(LNode *L,LNode *LinkList)
{
LNode *p,*q;
LNode *temper;//临时节点
p=L->next;
q=p->
#include<stdlib.h>
#include<stdio.h>
typedef struct LNode{
int num;
struct LNode *next;
}LNode;//定义链表的节点
void creat(LNode *L)
{
int i,count;//i用来计数,count用来确定链表的长度
printf("please put in the count :\n");
scanf("%d",&count);//输入链表的长度
printf("please put in the number:\n");
for(i=0;i<count;i++)
{
LNode *p;
p=(LNode *)malloc(sizeof(LNode));
scanf("%d",&p->num);//依次输入链表的数值
p->next=L->next;
L->next=p;
L=p;
}
}//创建链表,头节点为L
void print(LNode *L)
{
while(L!=NULL)
{
printf("%d ",L->num);
L=L->next;
}
printf("\n");
}//输出链表
void reverse(LNode *L,LNode *LinkList)
{
LNode *p,*q;
LNode *temper;//临时节点
p=L->next;
q=p->
(type)就是强制类型转换
(int)指强制转换为int,(LNode *)就是强制转换为指向LNode类型的pointer
将malloc(sizeof(LNode))分配的地址强制转换成指向LNode类型的pointer
typedef struct LNode{
int num;
struct LNode *next;
}LNode;//定义链表的节点
typedef 定义LNode为结构体的类型名称,与int,float功能一样,可以使用LNode定义数据类型。
所以LNode * L;的意思就是定义一个结构体类型的变量。
你想问什么啊?L=(LNode *)malloc(sizeof(LNode));生成一个指针啊!