vc++中创建链表的创建问题

2418人阅读
VC++学习(14)
定义测试的结构体:
struct CAccount
CString m_//名目
double m_//费用
链表定义单元引用
#include &PtrList.h&
定义链表:
CPtrList m_
操作示例:
CAccount* m_pAccount = new CA//创建结构体对象指针
switch(m_radio)
//插入操作
if(m_name.IsEmpty()||m_count&=0)
//判断插入信息的有效性
AfxMessageBox(&输入的费用信息不正确!&);
m_pAccount-&m_name = m_//将用户输入信息赋值给结构体对象
m_pAccount-&m_count=m_//PS:定义为结构体指针,故使用指针方式获取属性
m_accountlist.AddTail(m_pAccount);//将结构体对象加入到链表尾
m_name=&&;//编辑框复位
m_count=0.0;
UpdateData(false);
Reflesh();//更新显示
//去除表头操作
if(m_accountlist.GetCount())//链表不为空
m_accountlist.RemoveHead();//去除表头
m_name=&&;//复位
m_count=0.0;
UpdateData(false);
Reflesh();//更新显示
case 2: //去除表尾操作
if(m_accountlist.GetCount())//链表不为空
m_accountlist.RemoveTail();//去除表尾
m_name=&&;
m_count=0;
UpdateData(false);
Reflesh();//更新显示
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:284934次
积分:3963
积分:3963
排名:第5839名
原创:99篇
转载:33篇
评论:39条
(2)(6)(1)(6)(3)(1)(1)(1)(1)(1)(2)(6)(10)(4)(1)(2)(2)(12)(2)(10)(4)(1)(9)(7)(6)(4)(9)(18)&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!君,已阅读到文档的结尾了呢~~
程序设计链表与链表的基本操作
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
程序设计链表与链表的基本操作
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer--144.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口C语言题库(3)
题目:调用自定义函数creat读入第一部分学生信息建立链表A、调用自定义函数creat读入第二部分学生信息建立链表B,每个链表中的节点包括学号、成绩;然后调用自定义函数merge将两个链表以节点的学号升序合并为一个链表C。三个链表的内容均调用自定义函数print输出在屏幕上。
第一次代码():
int sum = 0;
/* User Code Begin(考生可在本行后添加代码,定义程序中使用的结构体类型、声明自定义函数的原型,行数不限) */
struct student
struct student *next;
struct student *creat(void);
struct student *merge(struct student *ah, struct student *bh);
/* User Code End(考生添加代码结束) */
/* print以规定的格式完成遍历显示指定的链表 */
void print(struct student *Head);
int main(void)
struct student *ah, *bh, *ac;
printf("创建链表A,请输入学号及成绩(均输入为0时表示停止):\n");
ah = creat();
printf("\n创建链表B,请输入学号及成绩(均输入为0时表示停止):\n");
bh = creat();
printf("\n链表A:");
print(ah);
printf("\n链表B:");
print(bh);
ac = merge(ah, bh);
printf("\n两个链表共有%d个人\n链表C:", sum);
print(ac);
void print(struct student *Head)
while (Head != NULL)
printf("%d,%d
", Head-&num, Head-&score);
Head = Head-&next;
/* User Code Begin(考生在此后完成自定义函数的设计,行数不限) */
struct student *creat(void)
struct student *pHead, *pNew, *p;
pHead = p = (struct student *)malloc(LEN);
p-&next = NULL;
printf("学生 %d: ", sum + 1);
pNew = (struct student *)malloc(LEN);
scanf("%d %d", &pNew-&num, &pNew-&score);
while (pNew-&num != 0 || pNew-&score != 0)
pNew-&next = p-&next;
p-&next = pN
printf("学生 %d: ", sum + 1);
pNew = (struct student *)malloc(LEN);
scanf("%d %d", &pNew-&num, &pNew-&score);
return pHead-&next;
struct student *merge(struct student *ah, struct student *bh)
struct student *p =
struct student *p1, *p2;
if (ah == NULL)
while (ah-&next != NULL)
ah = ah-&next;
ah-&next =
for (p1 = p1 != NULL; p1 = p1-&next)
for (p2 = p1-&next; p2 != NULL; p2 = p2-&next)
if (p1-&num & p2-&num)
p1-&num = p2-&
p1-&score = p2-&
p2-&score =
在链表中使用选择法排序:
for (p1 = p1 != NULL; p1 = p1-&next)
for (p2 = p1-& p2 != NULL; p2 = p2-&next)
if (p1-&num & p2-&num)
p1-&num = p2-&
p1-&score = p2-&
p2-&score =
链表的创建方法:
struct student *creat(void)
struct student *pHead, *pNew, *p;
pHead = p = (struct student *)malloc(LEN);
p-&next = NULL;
printf("学生 %d: ", sum + 1);
pNew = (struct student *)malloc(LEN);
scanf("%d %d", &pNew-&num, &pNew-&score);
while (pNew-&num != 0 || pNew-&score != 0)
pNew-&next = p-&next;
p-&next = pN
printf("学生 %d: ", sum + 1);
pNew = (struct student *)malloc(LEN);
scanf("%d %d", &pNew-&num, &pNew-&score);
return pHead-&next;
易错点:创建链表时while的条件为while (pNew-&num != 0 || pNew-&score != 0)
中间是||而不是&&
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:845次
排名:千里之外求VC强人过来帮忙做作业,1.欲在一个链表的中间节点Pointer之后插入一个新节点NEW,其链域为next,给出插入操作的链连接语句.2.下列表达式中,每一个字母代表一个运算量,请进行相应的转换.(1) 中缀转后缀(A+B)*D+E/(F+A*D)+C(2) 后缀转中缀A C-D/E A B*F+/+ 3.写出循环队列Q在下列运算中队列头和尾变化的情况.Q.front Q.rear初始状态 0 0E1进队E2进队E3进队出队出队E4进队
第一题:newPointer->next = Pointer->Pointer->next = newP第二题:(1)AB+D*EFAD*+/+C+(2)(A-C)/D+E/(A*B+F)第三题:
Q.rear初始状态
为您推荐:
其他类似问题
扫描下载二维码

我要回帖

更多关于 链表的创建 的文章

 

随机推荐