0
我想弄清楚如何为DNode编写一个名为DNode *DNode::bubble()
的成员函数,其中 DNode *head
可以对链表进行冒泡排序并返回新的头部。 我想使用成员函数void swap(DNode *that)
交换两个节点。如何使用交换功能为双向链表创建气泡排序?
这里是我迄今关于h和.cpp文件:
#ifndef DNODE_H
#define DNODE_H
class DNode {
public:
int key;
DNode *next;
DNode *prev;
void add(int key);
void print();
DNode();
DNode *bubble();
void swap(Dnode *that);
};
#endif
#include "DNode.h"
#include <cstdlib>
#include <iostream>
using namespace std;
void DNode::swap(DNode *that){
DNode *temp = this;
DNode *R1, *L1, *R2, *L2;
}
Dnode *Dnode::bubble(){
DNode *temp = this;
int count = 0;
while(start != NULL){
count++;
start = start->next;
}
for(int i = 0; i < count; i++){
}
}
我有一个问题,用什么是交换函数只是一个参数来交换节点列表。
你忘了2个节点之间交换的核心价值观,但这也不应该是一个大问题。 'int temp = this.key; this.key =但─>键; that-> key = temp;' –
@GeriPapi不是必需的:它是确定列表布局中位置的链接。当然,你可以采取相反的观点:只需交换密钥,不要打扰。这取决于列表节点的内存布局是否重要。 – user268396
正确,我的不好。 –