Ha593 2022-05-19 22:42 采纳率: 95.2%
浏览 22
已结题

C++的结构体struct和自定义函数的调用

怎样在main函数中调用Initlist(),并传入函数执行后的值?怎样输出Listsize(),Listlength()和Listhead()的返回值?

#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;
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()
{
Listsize();
Listlength();
Listhead();
return 0;
}

  • 写回答

1条回答 默认 最新

  • 吕布辕门 后端领域新星创作者 2022-05-19 23:03
    关注
    
    int main()
    {
        table t;
        Initlist();
        Listhead(t);
        int s=Listlength(t);
        return 0;
        
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

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

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效