-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlianbiao.c
73 lines (66 loc) · 1015 Bytes
/
lianbiao.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int a;
struct node *next;
}Node;
Node * create(Node *h,int n)
{
if(h)
{
int i;
Node *s =h;
for( i=1;i<n;i++)
{
Node *p =(Node *)malloc(sizeof(Node));
s->next=p;
p->next=NULL;
p->a=i+1;
s = p;
}
}
}
void nixu(Node *head)
{
if(head != NULL && head->next != NULL){
Node *a=head;
Node *b=head->next;
Node *c=NULL;
while(b)
{
c= b->next;
b->next = a;
a = b;
b=c;
}
head->next=NULL;
head = a;
while(head)
{
printf("%d",head->a);
head = head->next;
}
}}
Node * main()
{
Node* head=(Node *)malloc(sizeof(Node));
head->next=NULL;
head->a=0;
create(head,2);
/* xian shi lian biao
for( i=0;i<3;i++)
{
printf("%d",head->a);
head=head->next;
}
*/
/* lian biao ni xu*/
Node *b=head;
printf("b:%d\n",b->a);
nixu(head);
while(head)
{
printf("%d",head->a);
head=head->next;
}
}