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

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日