【发布时间】:2015-10-18 21:42:30
【问题描述】:
我试图弄清楚如何为 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++){
}
}
我遇到的问题是交换函数,它只用那个参数交换列表中的节点。
【问题讨论】:
标签: c++ sorting linked-list bubble-sort doubly-linked-list