文章
145
粉丝
217
获赞
21
访问
84.5k
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int data;
struct node *next;
}LNode,*LinkList;
//初始化链表
void InitList(LinkList &L,int n)
{
L = (LNode *)malloc(sizeof(LinkList));
L->next = NULL;
int i;
struct node *p;
for(i = 0 ;i < n; i++) //尾插法
{
struct node *t =(LNode *)malloc(sizeof(LinkList));
scanf("%d",&t->data);
if(L->next == NULL)
{
L->next = t;
p = t;
p->next = NULL;
}
else
{
t->next = p->next;
p->next = t;
p = t;
}
}
}
//交换
void SwapList(LinkList &L)
{
int i = 1,t;
struct node *p = L->next,*q;
while(p)
{
q = p->next;
if(i % 2 != 0 && q)
{
t = p->data;
p->data = q->data;
q->data = t;
}
i++;
p = p->next;
}
}
//输出链表
void Print(LinkList L)
{
struct node *p = L->next;
while(p)
{
printf("%d ",p->data);
p = p->next;
}
}
int main(...
登录后发布评论
暂无评论,来抢沙发