我该如何处理这个问题。我对使用链接列表相对较新并且遇到了这个问题。请帮忙 [英] How Do I Go About This Question. I Am Relatively New To Using Linked Lists And Came Across This Question. Please Help

查看:71
本文介绍了我该如何处理这个问题。我对使用链接列表相对较新并且遇到了这个问题。请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一家小型投资公司将数据存储到单一链接列表中。每个列表元素包括:

客户名字

客户唯一标识符

投资类型

投资金额

编写相应的结构并编写从列表中删除投资不良的客户(投资金额小于0的客户)的功能。该函数返回已删除列表成员的数量。

A small investment company stores data into a singly linked list. Each list element consists of:
Customer First name
Customer unique identifier
Investment type
Investment amount
Write the corresponding structure and Write the function that removes customer with bad investment (those with investment amount less than 0) from the list. The function returns the number of removed list members.

推荐答案

在链接列表中,所有项目都是链接的,因此如果删除一个,则链接会丢失。因此,如果你想删除一个,你需要前任和后继成功删除一个元素。



删除前:

前身 - > ; obsolet - >继承人



删除后:

前身 - >继承人



因此,如果您扫描删除元素,则需要替换链接。为此,您的代码必须具有已删除元素的前任和后继。



其余为锅炉板代码。检查缓冲区大小是否足以容纳所有数据。使用类(或结构)作为客户数据。它必须有一个前导和后继指针才能删除。
In a linked list all item are linked, so if you delete one the linkage gets lost. So if you want to delete one, you need predecessor and the successor to successfully remove one element.

before deletion:
predecessor -> obsolet -> successor

after deletion:
predecessor -> successor

So if you scan to remove a element you need to replace the linkage. For that your code must have the predecessor and successor of a removed element.

The rest is "boiler plate" code. Check that the buffer size is big enough for all data. Use a class (or struct) for the costumer data. It must have a predecessor and successor pointer for the deletion.


这篇关于我该如何处理这个问题。我对使用链接列表相对较新并且遇到了这个问题。请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆