数据结构——顺序表
2012-09-10 18:16
183 查看
#include <iostream> using namespace std; int a[9]={1,2,3,4,5}; int i; void insert(); void display(); void deleted(); void search(); void change(); int main() { cout<<"you should not input ZERO"<<endl; display(); insert(); display(); deleted(); display(); search(); change(); display(); return 0; } void insert()//you can use this method to insert a date { int date; int number; cout<<"the number you wanna insert:"<<endl; cin>>date; cout<<endl; cout<<"the date's location: "<<endl; cin>>number; for(int k=0;k<=(i-number+1);k++) { a[i+1-k]=a[i-k]; } a[number-1]=date; } void display()//you can use this method to display all the date { for(i=0;a[i]!=NULL;i++) { cout<<a[i]<<endl; } } void search()//you can use this method to search a date { int locationNUM; cout<<"the date's location"<<endl; cin>>locationNUM; cout<<a[locationNUM-1]<<endl; if(locationNUM>i) cout<<"Data overflow"<<endl; } void change()//you can use this method to change a date { int date,location; cout<<"change date"<<endl; cin>>date; cout<<"the date's location"<<endl; cin>>location; if(location-1>i) cout<<"Data overflow"<<endl; else a[location-1]=date; } void deleted()//you can use this method to delete a date { int date; int number; cout<<"the number you wanna delete:"<<endl; cin>>number; for(;number<i;number++) { a[number-1]=a[number]; } a[i-1]=NULL; }
相关文章推荐
- 4/1 数据结构 顺序表
- 数据结构(基本运算验证性实践路线)——顺序表
- 数据结构 顺序表
- 货物管理系统(数据结构顺序表)
- 数据结构-顺序表
- 数据结构之 将顺序表所有元素逆置,要求空间复杂度为O(1)
- 温故知新之数据结构顺序表
- 数据结构顺序表基本流程
- 数据结构顺序表操作示例
- 数据结构 顺序表
- 数据结构_顺序表相关操作C语言源代码
- 数据结构之用顺序表实现二叉树
- 数据结构——顺序表最大子段和动态规划法
- 数据结构-顺序表代码实现
- 数据结构之线性表2顺序表
- Java数据结构与算法—及实现 线性表 顺序表、链表、栈、队列详解
- 数据结构1.1-顺序表
- 【数据结构作业六a】建立一个顺序表,用顺序查找、折半查找的方法对其实施查找
- 链表 顺序表 C# Unity 数据结构
- 数据结构顺序表链表C++实现