首页 > 代码库 > 线性表的顺序存储
线性表的顺序存储
#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;
}
线性表的顺序存储