单链表的各种操作
代码如下:
#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
int data;
struct Node *next;
}Node,*LinkList;
//typedef struct Node node;
//typedef struct Node *List;
//
//*node
//List
void HeadInsertList(LinkList &L)
{
L=(Node*)malloc(sizeof(Node));
L->next=NULL;
int x;
scanf("%d",&x);
while(x!=9999)
{
//Node p;
Node *p=(Node*)malloc(sizeof(Node));
p->data=x;
//p->next=NULL;
p->next=L->next;
L->next=p;
scanf("%d",&x);
}
}
void PrintList(struct Node * L)
{
Node *p;
p=L->next;
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
}
int main()
{
LinkList L;
HeadInsertList(L);
PrintList(L);
/*
不对原始的n进行修改
int sum(int n);
sum(n);
对原始的n进行修改
int sum(int &n);//n.name n.sex n.age
sum(n);
int sum(int *n);//n->name n->sex n->age
sum(&n);
*/
return 0;
}

1万+

被折叠的 条评论
为什么被折叠?



