two problems about linked list

ledfok 2002-07-19 01:14:31
who can solve these two problems?try these if you have the knowledge of data structure for c++.solve it in c++,please.

Problem 1 .
Implement a sorting algorithm using a singly linked list. The
algorithm (known as the Insertion sort algorithm) works as follows:
1. It starts with an empty linked list.
2. When a first node is inserted to the list, the node is inserted at the head of the list.
3. To insert a new node, the algorithm traverses the linked list until it finds a specific
position to insert the new node by comparing the new node’s data value to each
existing node’s data value.
4. Traverses all the elements of the linked list to print out the sorted values. [optional]
5. Repeats steps 3 and 4 for each and every new node.
Implement the insertion sort algorithm in C++ to ascendingly sort integers. Your program
should receive an arbitrary number of input integers one by one until you interrupt or stop
your program (by pressing Ctrl-C, for example). For each input integer, the program prints
out the sorted list after inserting the value. The screen shot of your program may look like the
following:
$ a.out
== Insertion sort by [your name] ==
[Empty List]
Input an integer: 5
Sorted List : 5
Input an integer: 7
Sorted List: 5 7
Input an integer: 2
Sorted List: 2 5 7
Input an integer: 6
Sorted List: 2 5 6 7
Input an integer: 3
Sorted List: 2 3 5 6 7
Also answer the following questions (as the comments at the end of your C++ program) :
� Explain the input sequences that will result in the best and the worst algorithmic
performances, in terms of the number of comparisons required.
� If there are N input values to be sorted, what is the best case complexity and what is the
worse case complexity, in terms of N ?


Problem 2
Implement the doubly circular linked list for integers in C++. Provide the following DCLL operations as the method members of the DCLL class :
1. Add a node at the head of the list
2. Add a node at the tail of the list (i.e. at head->previous)
3. Add a node after a specific n-th node (e.g. after the 4-th node). If such node does not
exist, simply deny the operation
4. Delete a node from the head of the list
5. Delete a node from the tail of the list
6. Delete a specific n-th node (e.g. delete the 5-th node). If such node does not exist, simply
deny the operation.
7. Delete all the nodes that have a specific value (i.e. yes, there can be duplicate nodes)
8. Determine if the list contain a particular value and how many duplicate nodes there are
9. Traverse the list in a forward direction (i.e. from head to tail)
10. Traverse the list in a backward direction (i.e. from tail to head)
Create a user interface in the main() function that is similar to the singly linked list (sll.cc)
example given on the class web page. The user interface should provide the above DCLL
operations appearing in such order. After applying each operation, your DCLL must still
remain consistent, i.e. all the pointers point to where they are supposed to.
...全文
104 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
含冰蓄冷空调的冷热电联供型微网多时间尺度优化调度(Matlab代码实现)内容概要:本文介绍了含冰蓄冷空调的冷热电联供型微网多时间尺度优化调度的Matlab代码实现方法,重点围绕电力系统中考虑楼宇空间布局的集群划分与优化调度问题展开,涵盖冷、热、电多能协同供应与储能调节机制。通过多时间尺度(如日前、日内、实时)的优化模型,实现能源利用效率提升与运行成本降低的目标。文中还提及相关智能优化算法的应用,如改进灰狼算法、多目标粒子群算法等,用于解决复杂的非线性调度问题,并提供了完整的Matlab仿真资源与案例复现支持。; 适合人群:具备一定电力系统、能源工程或自动化背景的研究生、科研人员及从事微网优化、综合能源系统设计的工程技术人员,熟悉Matlab编程与基本优化算法者更佳。; 使用场景及目标:①用于科研项目中冷热电联供微网系统的建模与仿真;②支撑论文复现与算法改进,特别是在多时间尺度调度、需求响应、储能优化等领域;③辅助实际工程中微网能量管理系统的设计与决策分析; 阅读建议:建议结合文档提供的网盘资源进行代码实践,重点关注模型构建逻辑与算法实现细节,配合YALMIP+CPLEX等工具包调试优化问题,同时参考文中列举的SCI/EI论文复现案例深化理解。

33,029

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧