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;
}

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

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;
}