数据结构-->c构建线性表
来源:互联网 发布:诺基亚e66软件 编辑:程序博客网 时间:2024/06/05 02:17
#include <stdio.h>#include <stdlib.h>#include <windows.h>/* -------------------------- VER || 1.1 DATA || 3/11/2017 AUTHER || WUD --------------------------*/static int MAXSIZELINE;typedef int Status;typedef int Elemtype;typedef struct{ Elemtype *elem; int len; int MAXSIZE;} Line;ShowProgram(){ //HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); //SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_WHITE); int j=0; for(j; j<27; j++) { printf("-"); Sleep(3); } printf("\n"); printf("VER || 1.1\n"); printf("FINIDATA || 3/11/2017\n"); printf("AUTHER || WUD\n"); for(j=0; j<27; j++) { printf("-"); Sleep(3); } printf("\n"); Sleep(200);}Status InitLine(Line *L){ //int MAXSIZELINE; HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN); printf("Hello, Please input The Size of Line: "); scanf("%d",&MAXSIZELINE); (*L).elem = (Elemtype *)malloc(MAXSIZELINE*sizeof(Elemtype)); if ((*L).elem==0) { printf("InitLine ERROR, Check your original code about malloc :( n"); exit(0); } else if ((*L).elem != 0) { Sleep(100); printf("InitLine Successfully :)\n"); Sleep(30); printf("The space of Line is %d :)\n\n", MAXSIZELINE); (*L).len = 0 ; (*L).MAXSIZE = MAXSIZELINE ; } return 0 ;}void InsertLine(Line *L){ HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_BLUE); int temp; for((*L).len = 0; (*L).len < (*L).MAXSIZE; (*L).len++) { printf("Please input the %d number into the Line : ", (*L).len); scanf("%d", &temp); (*L).elem[(*L).len] = temp; //(*L).len+=1; if ((*L).len == (*L).MAXSIZE) { printf("InsertLine Successfully :)\n"); printf("Check your Line.MAXSIZELINE?=MAXSIZE, Maybe You Need To Create Some New Space :)\n"); } }}void DeleteData(Line *L){ int location; printf("Please Input The Location That You Want To Delete: "); scanf("%d", &location); (*L).elem[location] = 0; //(*L).len=(*L).len-1; printf("DELETE SUCCESFULLY :)\n"); //printf("Now the size of line is %d\n\n\n",(*L).len);}void InsertData(Line *L){ int location; int data,stmp,space,j; HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN); Sleep(30); printf("Please Input The Location That You want to Insert: "); scanf("%d", &location); Sleep(30); printf("The Location Is %d\n", location); Sleep(30); printf("Please Input The DATA You Want To Insert: "); scanf("%d", &data); printf("The Date is %d\n", data); Sleep(30); printf("Now You Need To Increase Some Space So Save Your Date, Please Input INCREAMENT SPACE:"); Sleep(30); scanf("%d", &space); (*L).elem = (Elemtype*)realloc((*L).elem,((*L).len+space)*sizeof(Elemtype)); Sleep(30); printf("New Space is %d\n", MAXSIZELINE+space); (*L).len = (*L).len+space; Sleep(30); printf("Save Data!\n"); for (j = 0; j<80; j++) { printf("="); Sleep(1); } printf("\n"); for(location=location; location<=(*L).MAXSIZE+1; location++) { stmp = (*L).elem[location]; (*L).elem[location] = data; data = stmp; } (*L).elem[(*L).len+1] = (*L).elem[(*L).len]; for (j = 0; j<80; j++) { printf(">"); Sleep(1); } printf("\n"); for (j=0; j<(*L).len-1; j++) { printf("%d--->", (*L).elem[j]); Sleep(30); if(j == (*L).len-2) { printf("%d\n",(*L).elem[j+1]); } }//if (j==(*L).len-1){printf("%d\n", L.elem[j]);} for (j = 0; j<80; j++) { printf(">"); Sleep(1); } printf("\n");}Status FreeLine(Line *L){ free((*L).elem); (*L).elem=NULL; (*L).len=0; (*L).MAXSIZE=0; printf("FreeLine SUCCESSFULLY :)\n"); Sleep(30); printf("Now the Line Size is %d\n\n", (*L).elem); return 1;}Status DisplayLine(Line L){ int flag = 0; int i, j; for (i=0; i<L.len; i++) { printf("The %d number in this Line is %d \n", i, L.elem[i]); } HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED); printf("\nDescribe Line \n"); for (j = 0; j<80; j++) { printf(">"); Sleep(1); } printf("\n"); for (j = 0; j<L.len-1; j++) { printf("%d--->", L.elem[j]); Sleep(30); //printf("%d,%d",j,L.len); if (j==L.len-2)printf("%d\n", L.elem[j+1]); flag = 1; } for (j = 0; j<80; j++) { printf(">"); Sleep(1); } printf("\n"); return flag;}int main(){ int point; ShowProgram(); HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED); printf("Press 1 to continue else exit :)"); while (scanf("%d",&point)!=EOF) { if (point!=1) { exit(0); } else { Line L; InitLine(&L); InsertLine(&L); Sleep(1000); int flag = DisplayLine(L); DeleteData(&L); DisplayLine(L); InsertData(&L); if (flag == 1)printf("\nProgram Run Successfully!\n"); else printf("ERROR PROGRAM! check your program!\n"); Sleep(30); FreeLine(&L); printf("Press 1 To continue else Exit!"); } } return 0 ; //system(pause);}
Markdown编辑器还是有bug的:)
阅读全文
0 0
- 数据结构-->c构建线性表
- 数据结构-线性表 (C++)
- 数据结构线性表c
- C - 数据结构 - 线性表
- C语言构建线性表
- Linux C 数据结构---线性表
- 数据结构之线性表(C#)
- Linux C 数据结构---线性表
- 复习(数据结构):线性表 : C
- 《数据结构(C语言版)》- 线性表
- 数据结构--线性表C实现
- 使用数组构建线性表的顺序表数据结构
- 数据结构2:线性表的构建和基本操作
- C数据结构-线性表之顺序表
- 线性表数据结构C语言实现
- 数据结构C/C++线性表和单链表
- C语言数据结构--(线性表一)
- 数据结构与算法(C#)--线性表
- Okhttp解析(二)网络请求的执行
- redis图形界面管理工具-RedisStudio
- Python生成器
- (01)Structs初学笔记——开篇
- git命令行
- 数据结构-->c构建线性表
- Linux CentOS6.7 jdk1.8.0_11 安装Elasticsearch5.0.1
- treeview 使用
- 刷新托盘图标
- 0基础lua学习(十三)Metatable
- 单例设计模式
- HDU-2001(两点距离问题)
- win7 python3.6安装教程及环境配置
- Mybatis入门级教程(一)