数据结构

这篇博客包含了多个关于数据结构的C++编程练习,包括链表操作、双向链表、栈、队列以及哈夫曼树等。通过实例展示了如何创建、插入、反转链表,以及解决回文字符串检测等问题。此外,还讨论了二叉树的层次遍历算法。
摘要由CSDN通过智能技术生成
 
习题1
Chapter 1  P 18   1.7
1.7 Does every problem have an algorithm?
Every problem does not have an algorithm.
 
 1.8
1.8 Does every algorithm have a C++ program?
By “algorithm” we mean something composed of steps are
of a nature that they can be performed by a computer. If so, than any algorithm
can be expressed in C++.
 
习题2
Chapter 4  P 135   4.3
4.3 Write a series of C++ statements to create a list capable of holding 20 elements and which actually stores the following list <2,3|15,5,9>.
Solution:
list L1(20);
L1.append(2);
L1.append(23);
L1.append(15);
L1.append(5);
L1.append(9);
L1.next();
L1.next();
 
 4.4
4.4 Write a function to interchange the first two elements in the right partition of a list.
Solution:
void switch(List<Elem> L1) {
Elem temp;
if (!L1.remove(temp)) ERROR;
L1.next();
L1.insert(temp);
}
 
 4.5
4.5 Add to the LList class implementation a member function to reverse the order of the elements on the list,run time ⊙(n).
template <class Elem>
void LList<Elem>::reverse() { // Reverse list contents
if(head->next == NULL) return;
// First, fix f
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值