最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 正文

C++顺序表,增删查

来源:动视网 责编:小OO 时间:2025-09-29 23:32:35
文档

C++顺序表,增删查

C++顺序表增删查!!//Link_SeqList.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"#include"iostream"usingnamespacestd;constintMAXSIZE=100;intflag=0;//定义一个顺序表结构体typedefstruct{intdata[MAXSIZE];intlast;}SeqList;//定义一个顺序表SeqListL;//顺序表初始化Se
推荐度:
导读C++顺序表增删查!!//Link_SeqList.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"#include"iostream"usingnamespacestd;constintMAXSIZE=100;intflag=0;//定义一个顺序表结构体typedefstruct{intdata[MAXSIZE];intlast;}SeqList;//定义一个顺序表SeqListL;//顺序表初始化Se
C++顺序表增删查!!

// Link_SeqList.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include "iostream"

using namespace std;

const int MAXSIZE=100;

int flag=0;

//定义一个顺序表结构体

typedef struct

{

    int data[MAXSIZE];

    int last;

}SeqList;

//定义一个顺序表

SeqList L;

//顺序表初始化

SeqList *Init_SeqList()

{

    SeqList *L;//定义一个指向SeqList 类型的指针变量

    L=(SeqList *)malloc(sizeof(SeqList));//通过这个操作让L获得顺序表的存储空间,L存放的是顺序表的地址

L->last=-1;//表中last 指针置为-1,表示表中没有数据元素

    return L;

}

//顺序表中插入元素

int Insert_SeqList(SeqList *L,int i,int x)

{

    int j;

if(L->last==MAXSIZE-1)

    {

        printf("表满!");

        flag=-1;

    }

if(i<1||i>L->last+2)

    {

        printf("位置错误!");

        flag=0;

    }

for(j=L->last;j>=i-1;j--)

    {

     L->data[j+1]=L->data[j];

    }

L->data[i-1]=x;

L->last++;

    flag=1;

    return flag;

}

//顺序表中删除一个元素

int Delete_SeqList(SeqList *L,int i)

{

    int j;

if(i<1||i>L->last+1)

    {

     cout<<"不存在第i个元素!"<        flag=0;

    }

for(j=i;j<=L->last;j++)

     L->data[j-1]=L->data[j];

L->last--;

    flag=1;

    return flag;

}

//在顺序表中查找一个元素

int Location_SeqList(SeqList *L,int x)

{

    int i=0;

while(i<=L->last&&L->data[i]!=x)

    i++;

if(i>L->last)

    {

     cout<<"查找失败!"<        flag=-1;

        return -1;

    }

    else return i;

}

int main(int argc, char* argv[])

{

    SeqList *L;

    int i,x,count=0;    

    L=Init_SeqList();    

while(count<5)

    {

     cout<<"please input i,x:"<     cin>>i;

     cin>>x;

loop1:    Insert_SeqList(L,i,x);

        count++;

        if(flag==-1||flag==0)

        {

            count--;

            goto loop1;

        }

    }

cout<<"The SeqList L->last=="<last+1<cout<<"The SeqList's menber:"<for(i=0;ilast+1;i++)

     cout<<"L->data["<data[i]<    

cout<<"Please input x:"<cin>>x;    

cout<<"x的位置:"<loop2: cout<<"Please input i:"<cin>>i;

    Delete_SeqList(L,i);

    if(flag==0)

    {

     cout<<"第i个元素不存在!请重新输入:"<        goto loop2;

    }

cout<<"The SeqList L->last=="<last+1<     cout<<"The SeqList's menber:"<for(i=0;i<=L->last;i++)

     cout<<"L->data["<data[i]<    return 0;

}

文档

C++顺序表,增删查

C++顺序表增删查!!//Link_SeqList.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"#include"iostream"usingnamespacestd;constintMAXSIZE=100;intflag=0;//定义一个顺序表结构体typedefstruct{intdata[MAXSIZE];intlast;}SeqList;//定义一个顺序表SeqListL;//顺序表初始化Se
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top