- 1、本文档共82页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
第十章结构体与共用体;10.1.1结构体类型的定义;举例;10.1.2结构体变量的定义;存储空间示意图;10.1.2结构体变量的定义;10.1.2结构体变量的定义;10.1.2结构体变量的定义;10.1.2结构体变量的定义;■可以使用struct goods去定义结构体变量, 也可以使用kind去定义结构体变量。比如:
struct goods g1;
kind g2;;10.1.3结构体变量的使用;10.2.1结构体数组的定义
■ (2)定义结构体类型的同时定义数组 struct goods
{
int number;
char name[10]; float price;
}g[10];;10.2.2结构体数组的初始化;void main()
(
struct goods
{
int number;
char name[10]; float price;
} g[10];
int i, max, min;
float average=0.0;
for(i=0;i10;i++)
(
printf(”输入商品编号、名称、单价:\n”); scanf(n%d%s%fn, g[i].number,
g[i].name,g[i].price);;10.3结构体类型指针
■定义方法:
struct结构体名*指针变量名;;10.3.2指向结构体数组的指针;void main();p=g; pmax=pmin=g;
for(i=0;i10;i++)
( if(p-pricepmax-price)
pmax=p;
if(p-pricepmin-price)
pmin= p;
average=average+ p-price;
P++;
}
average=average/10;
printf(66the max price is:%d,%s,%f\n”, pmax-number9 pmax?name, pmax-price);
printf(66the min price is:%d,%s,%f\n, pmin-number^pmin-name^pmin-price);
printf(uthe average price is:%f\n”, average);
};10.4.1结构体变量的成员作函数实参;#include vstdio?h #include string.h struct student;void main()
{
struct student stu; stu.num=10446;;#include vstdio.h〉
#include string.h struct student
(
int num;
char name[20];
char sex;
int score[3];
};
void fun(struct student stu)
(
stunum= 10447;
strcpy(stu.name5 lisi”); stu.sex=W‘;
stu.score[0]=60; stu.score[l]=60; );void main()
{
struct student stu; stu.num=10446;;-| p /I Q 4:巨女士土幻/7卜白4:匕4:丄亿3 2^米打会米
#include vstdio.h〉;1 C void main()
(
struct student stu, *p; stu.num=10446;
strcpy(stu.name, “zhangsan”); stu.sex= W;;10.5链表;10.5.1静态链表;struct goods
{
char name[10]; float price;
struct goods *next;;10.5.2动态链表;10.5.2.1空间分配与回收函数;10.5.2.2建立和输出链表;10.5.2.2建立和输出链表;10.5.2.2 B立和输出链表
void PrintList(struct goods * head)
{
struct goods *p; p=head;
while(p!=NULL)
(
printf( % s, % .2An^\p-name,p-price);
p-p-next;
}
}
void main()
(
struct goods * head;
printf(“请输入商品名称、单价,名称为end表示结束输入:\n”);
head=CreateList();
printf(“输出链表,商品信息如下:\n”);
PrintList(head);
};10.5.2.2建立和输出链表
■程序运行时的情况:;程序执行过程;程序执行过程;程序执行过程;程序执行过程;程序执行过程;程序执行过程;10.5.2.3查找链表结
文档评论(0)