数据结构源代码(全)

更新时间:2023-07-24 00:08:21 阅读: 评论:0

/*
顺序表的操作
#include<iostream>
#include<stdlib.h>
using namespace std;
Relea 13.12  rev 9501 (2013/12/25 19:25:45)  gcc 4.7.1 Windows/unicode - 32 bit
how to forget
#define MAX_SIZE 100
typedef struct
{
    int *emel;
    int lenth;
}Sq;
void init(Sq &l);
void create(Sq &l);
void trval(Sq &l);
void find_value(Sq &l);
void find_position(Sq &l);
void inrt(Sq &l);
heal the world下载void dele(Sq &l);
int main()
{
    Sq l;
    init(l);
    create(l);
    trval(l);
    find_value(l);
    find_position(l);
    inrt(l);
    trval(l);
    dele(l);
    trval(l);
    return 0;
}
void init(Sq &l)
{
    l.emel =new int[MAX_SIZE];
    l ==NULL)
    {
        cout<<"\t申请空间失败!"<<endl;
        exit(1);
    }
    l.lenth=0;
    cout<<"\t成功申请空间!该顺序表的长度目前为:"<<l.lenth<<endl;
}
void create(Sq &l)
{
    cout<<"\t请输入你想输入元素的个数:";
    int x;
    cin>>x;
    if((x<1)&&(x>MAX_SIZE))
    {
        cout<<"\t你说输入的数不在范围里"<<endl;
        return;
    }
    int i;
    for(i=0;i<x;i++)
    {
        cin>&l[i];
frosting
    }
    l.lenth=x;
    cout<<"\t成功赋值!"<<endl;
}
void trval(Sq &l)
{
    int i;
捐赠支出    cout<<"l(";
snake什么意思
    for(i=0;i<l.lenth;i++)
    {
        cout<&l[i]<<" ";
    }
    cout<<")"<<"  该顺序表现在的长度为:"<<l.lenth<<endl;
}
void find_value(Sq &l)
{
    int x,t=0;
    cout<<"\t请输入你要查找的值:";
liquidmetal    cin>>x;
    int i;
    for(i=0;i<l.lenth;i++)
    {
        l[i]==x)
        {
almost human
            t=1;
            cout<<"\t成功找到该元素,它是顺序表的第"<<i+1<<"个元素!"<<endl;
        }
    }
    if(t==0)
    {
        cout<<"\t无该元素!"<<endl;
    }
}
void find_position(Sq &l)
{
    int x;
    cout<<"\t请输入你要查找的位置:";
    cin>>x;
    int i;
    if((x<1)||(x>l.lenth))
    {
ossine
        cout<<"\t输入的值不在范围内!"<<endl;
        return;
    }
conclusion    for(i=1;i<=l.lenth;i++)
    {
        if(i==x)
        {
            cout<<"\t成功找到该元素,该值是"<&l[i-1]<<endl;
        }
    }
}
void inrt(Sq &l)
{
    int i,x,y;
    cout<<"\t请输入你要插入的位置";
    cin>>x;
    cout<<"\t请输入你要插入的值";
    cin>>y;
    if((x<1)||(x>l.lenth))
    {
        cout<<"\t输入的值不在范围内!"<<endl;
        return;
    }
    if(x==l.lenth)
牛津大学学费    {
        l.emel[l.lenth]=y;
        l.lenth=l.lenth+1;
        return;

本文发布于:2023-07-24 00:08:21,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/1113564.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:输入   顺序   元素   空间   申请   支出   捐赠   长度
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图