线性表的顺序存储
来源:互联网 发布:linux root为用户授权 编辑:程序博客网 时间:2024/04/30 04:23
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#define N 500010
#define INF 10000000
#define LL long long
#define eps 10E-9
#define mem(a) memset(a,0,sizeof(a))
#define w(a) while(a)
#define s(a) scanf("%d",&a)
#define ss(a,b) scanf("%d%d",&a,&b)
#define sss(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define MAXN 9999
#define MAXSIZE 10
#define DLEN 4
#define MAXN 9999
#define MAXSIZE 10
#define DLEN 4
using namespace std;
struct mylist//只一个结构体 和数组差不多。。
{
int data[MAXN];//存数据
int length;//数据个数
} node;
void myinsert(int pos, int cnt)
{
for(int i = node.length ; i>=pos; i--)
{
node.data[i+1] = node.data[i];
}
node.data[pos]=cnt;
node.length++;
cout<<"success!"<<endl;
for(int i=1; i<=node.length; i++)
{
cout<<node.data[i]<<" ";
}
cout<<endl;
}
void mydelete(int pos)
{
for(int i=pos; i<node.length; i++)
{
node.data[i]=node.data[i+1];
}
node.length--;
cout<<"success!"<<endl;
for(int i=1; i<=node.length; i++)
{
cout<<node.data[i]<<" ";
}
cout<<endl;
}
void myquery(int pos)
{
cout<<node.data[pos]<<endl;
}
int main()
{
int num;
printf("input the length of data\n");
cin>>num;
node.length=num;
cout<<"input all the data"<<endl;
for(int i=1; i<=num; i++)
{
cin>>node.data[i];
}
int pos, cnt;
cout<<"input the postion and data of insert"<<endl;
cin>>pos>>cnt;
myinsert(pos, cnt);
cout<<"input the postion of the data you want to dalete"<<endl;
cin>>pos;
mydelete(pos);
cout<<"input the postion of the data you want to query"<<endl;
cin>>pos;
myquery(pos);
return 0;
}
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#define N 500010
#define INF 10000000
#define LL long long
#define eps 10E-9
#define mem(a) memset(a,0,sizeof(a))
#define w(a) while(a)
#define s(a) scanf("%d",&a)
#define ss(a,b) scanf("%d%d",&a,&b)
#define sss(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define MAXN 9999
#define MAXSIZE 10
#define DLEN 4
#define MAXN 9999
#define MAXSIZE 10
#define DLEN 4
using namespace std;
struct mylist//只一个结构体 和数组差不多。。
{
int data[MAXN];//存数据
int length;//数据个数
} node;
void myinsert(int pos, int cnt)
{
for(int i = node.length ; i>=pos; i--)
{
node.data[i+1] = node.data[i];
}
node.data[pos]=cnt;
node.length++;
cout<<"success!"<<endl;
for(int i=1; i<=node.length; i++)
{
cout<<node.data[i]<<" ";
}
cout<<endl;
}
void mydelete(int pos)
{
for(int i=pos; i<node.length; i++)
{
node.data[i]=node.data[i+1];
}
node.length--;
cout<<"success!"<<endl;
for(int i=1; i<=node.length; i++)
{
cout<<node.data[i]<<" ";
}
cout<<endl;
}
void myquery(int pos)
{
cout<<node.data[pos]<<endl;
}
int main()
{
int num;
printf("input the length of data\n");
cin>>num;
node.length=num;
cout<<"input all the data"<<endl;
for(int i=1; i<=num; i++)
{
cin>>node.data[i];
}
int pos, cnt;
cout<<"input the postion and data of insert"<<endl;
cin>>pos>>cnt;
myinsert(pos, cnt);
cout<<"input the postion of the data you want to dalete"<<endl;
cin>>pos;
mydelete(pos);
cout<<"input the postion of the data you want to query"<<endl;
cin>>pos;
myquery(pos);
return 0;
}
1 0
- 线性表的顺序存储
- 顺序存储的线性表
- 线性表的顺序存储
- 线性表的顺序存储
- 线性表的顺序存储
- 线性表的顺序存储
- 线性表的顺序存储
- 线性表的顺序存储
- 线性表的顺序存储
- 线性表的顺序存储
- 线性表的顺序存储
- 线性表的顺序存储
- 线性表的顺序存储
- 线性表的顺序存储
- 线性表的顺序存储
- 线性表的顺序存储
- 线性表的顺序存储
- 线性表的顺序存储
- vc++下 asci函数与unicode对照
- UNION和UNION ALL区别
- HDU-2028
- Android自定义软键盘的实现
- c#第一次作业
- 线性表的顺序存储
- 黑马程序员--关于控件平移缩放旋转的总结
- 如何写简单的Makefile
- 黑马程序员-IOS学习笔记 结构体的嵌套demo
- 浏览器输入网址后台怎么运行
- 在android中创建包含对象数组对象List 的Parcelable
- It's because your R is too old
- HashMap和Hashtable的区别
- Mysql常用函数