e1_link.cpp
来自「数据结构中有关单链表操作的源码」· C++ 代码 · 共 57 行
CPP
57 行
// HELLO.cpp : Defines the entry point for the console application.
//
#include "stdio.h"
#include "malloc.h"
#include "stdlib.h"
#include "LinkList.h"
Status LinkInverse(LinkList &L){
LinkList p;
p=L->next; //record the first node
L->next=NULL;
while(p){ //from the first node to the end node
ListInsert_L(L, 1, p->data); // insert always before the first node
p=p->next;
}
return OK;
}
int main(int argc, char* argv[])
{
LinkList L1, p;
int x,i;
InitList_L(L1);
printf("please enter 10 integers:\n");
for(i=1;i<=10;i++) { //输入表的内容
scanf("%d",&x);
ListInsert_L(L1,i,x);
}
p=L1->next;
while(p){
printf("%d,", p->data);
p=p->next;
}
LinkInverse(L1);
printf("\n逆置后表中的10个整数为:");
p=L1->next;
while(p) { // output the inverse result
printf("%d,",p->data);
p=p->next;
}
getchar();
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?