Ha593 2022-05-20 13:47 采纳率: 95.2%
浏览 16
已结题

C++数据结构顺序表

img


请问这些问题应该怎么解决

#include <stdio.h>
#include

using namespace std;
#define Size 8 //顺序表的容量大小

struct table {
  int size; //顺序表的容量大小(形参)
  int length;//顺序表的有效长度,及数组中的元素个数
  int* head;//动态数组
};

void Initlist()
{
  table t;
  t.length = 0;
  t.size = Size;
  t.head = new int[t.size];

  int i;
  int n=0;
  cout << "输入" << n;
    cin >> n;
  for (i = 0; i < n; i++)
  {
    cout << endl << "输入第" << i + 1 << "个数据:";
    cin >> t.head[i];
    t.length++;
  }
};

int Listsize(table t) //求顺序表的容量大小
{
  return t.size;
}

int Listlength(table t)//求顺序表中数组的元素个数
{
  return t.length;
}

int Listhead(table t)//求顺序表中数组的各元素
{
  int i;
  int n = 0;
  for (i = 0; i < n; i++)
    return t.head[i];
}

int _main()
{
  table t;
  Initlist();
  Listhead(t);
  int s = Listlength(t);
  int l = Listsize(t);
  return 0;
}

  • 写回答

1条回答 默认 最新

  • 吕布辕门 后端领域新星创作者 2022-05-20 13:56
    关注

    给你改了一下,可以正常运行

    img

    
    #include <stdio.h>
    #include <iostream>
    
    using namespace std;
    #define Size 8 //顺序表的容量大小
    
    struct table {
      int size; //顺序表的容量大小(形参)
      int length;//顺序表的有效长度,及数组中的元素个数
      int* head;//动态数组
    };
    
    void Initlist()
    {
      table t;
      t.length = 0;
      t.size = Size;
      t.head = new int[t.size];
    
      int i;
      int n=0;
      cout << "输入" << n;
        cin >> n;
      for (i = 0; i < n; i++)
      {
        cout << endl << "输入第" << i + 1 << "个数据:";
        cin >> t.head[i];
        t.length++;
      }
    };
    
    int Listsize(table t) //求顺序表的容量大小
    {
      return t.size;
    }
    
    int Listlength(table t)//求顺序表中数组的元素个数
    {
      return t.length;
    }
    
    int Listhead(table t)//求顺序表中数组的各元素
    {
      int i;
      int n = 0;
      for (i = 0; i < n; i++)
        return t.head[i];
    
    return t.head[0];
    }
    
    int main()
    {
      table t;
      Initlist();
      Listhead(t);
      int s = Listlength(t);
       cout << endl << s;
      int l = Listsize(t);
       cout << endl << l;
      return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 5月28日
  • 已采纳回答 5月20日
  • 创建了问题 5月20日

悬赏问题

  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题