/*Copyright 2011 by wuwennongdao, All rights reserved
*Email: liuy0711@foxmail.com
*Blog: http://blog.csdn.net/algorithm_only
*/
#include <stdio.h>
#include <stdlib.h>
#include "linklist.h"
int main()
{
linklist l;
int n, number, e;
init_list(&l);
system("clear"); //for linux
// system("cls"); //for windows
printf("\n");
printf("*****************************************************************\n");
printf("* This progrom is an operation for linklist. *\n");
printf("* Programed by wuwennongdao and request for comments. *\n");
printf("* Email:liuy0711@foxmail.com *\n");
printf("* Blog: blog.csdn.net/algorithn_only *\n");
printf("*****************************************************************\n\n");
printf("Please select one operation blow:\n");
printf("--------------------------------------------------------------\n");
printf(" 1. Create the linklist fron head.\n");
printf(" 2. Create the linklist from tail.\n");
printf(" 3. Output linklist's all elements.\n");
printf(" 4. Get the length of the linklist.\n");
printf(" 5. Get element by location in the linklist.\n");
printf(" 6. Search elements in the linklist.\n");
printf(" 7. Insert an element in the linklist.\n");
printf(" 8. Delete an element from the linklist.\n");
printf(" 9. Clear the linklist to NULL.\n");
printf(" 10. Destory the linklist.\n\n");
printf(" 0. Display the options again.\n");
printf(" -1. Quit the program.\n");
printf("---------------------------------------------------------------\n");
for(;;) {
printf("[linklist]# ");
scanf("%d", &number);
switch (number) {
case 1:
printf("input how much node you want to create: >");
scanf("%d", &n);
printf("Please input %d elements: >", n);
create_list_l(l, n);
printf("The linklist is:");
output_list(l);
break;
case 2:
printf("input how much node you want to create: >");
scanf("%d", &n);
printf("Please input %d elements: >", n);
create_list_r(l, n);
printf("The linklist is:");
output_list(l);
break;
case 3:/*
if (!l) {
printf("Please choice 1 or 2 to initial linklist first!\n");
break;
}*/
printf("The linklist is:");
output_list(l);
break;
case 4:
printf("The length of the linklist is %d\n", get_list_length(l));
break;
case 5:
printf("Please input the position where you want to get element: >");
scanf("%d", &n);
if ( ERROR == get_node(l, n, &e))
printf("Get Element ERROR!\n");
else
printf("The element at %d is %d\n", n, e);
break;
case 6:
printf("Please input the value of Element which you want to search: >");
scanf("%d", &e);
if ((n = search_node(l, e)) == ERROR)
printf("There is no %d in the linklist.\n", e);
else
printf("The Element %d is located at %d in the linklist.\n", e, n);
break;
case 7:
printf("Please input the postion and value of Element you want to insert: >");
scanf("%d %d",&n,&e);
if (ERROR == insert_node(l, n, e))
printf("Insert ERROR!\n");
else {
printf("After insert %d,the linklist is:", e);
output_list(l);
}
break;
case 8:
printf("Please input the postion where you want to delete element: >");
scanf("%d",&n);
if (ERROR == del_node(l, n, &e))
printf("Delete ERROR!\n");
else {
printf("After Delete %d,the linklist is:", e);
output_list(l);
}
break;
case 9:
clear_list(l);
printf("After clear,the list is:");
if (l->next == NULL)
printf("NULL\n");
else
output_list(l);
break;
case 10:
destory_list(l);
break;
case 0:
printf("Please select one operation blow:\n");
printf("--------------------------------------------------------------\n");
printf(" 1. Create the linklist fron head.\n");
printf(" 2. Create the linklist from tail.\n");
printf(" 3. Output linklist's all elements.\n");
printf(" 4. Get the length of the linklist.\n");
printf(" 5. Get element by location in the linklist.\n");
printf(" 6. Search elements in the linklist.\n");
printf(" 7. Insert an element in the linklist.\n");
printf(" 8. Delete an element from the linklist.\n");
printf(" 9. Clear the linklist to NULL.\n");
printf(" 10. Destory the linklist.\n\n");
printf(" 0. Display the options again.\n");
printf(" -1. Quit the program.\n");
printf("---------------------------------------------------------------\n");
break;
case -1:
printf("\n--------Thank you for using! bye bye--------\n\n");
return 1;
default:
printf("Error options!\n");
break;
}
}
return 0;
}
线性表链式表示及实现源码
5星 · 超过95%的资源 需积分: 10 200 浏览量
2011-11-12
19:24:46
上传
评论 1
收藏 8KB ZIP 举报
algorithm_only
- 粉丝: 91
- 资源: 16
最新资源
- 基于Python的图像阴影检测与去除源码(高分期末大作业项目).zip
- 基于C++/Qt实现的井字棋游戏
- 基于 Python 编程语言的 Web 框架Django
- Python和Flask实现的基于体检数据的城市公共健康可视分析系统源码+使用说明.zip
- 基于python实现的华为智慧工地-安全帽检测
- buck-boost_2023-12-16_12-12-13.eprj
- 后端开发关于数据库和API开发的介绍
- 机器学习和数据挖掘课程设计-米其林餐厅数据挖掘管理系统源码+使用文档说明.zip
- html html html展示我与ai的对化
- 数据结构课程设计-全国交通出行咨询模拟系统C语言实现源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈