冒泡排序算法产生错误的输出
Bubble sort algorithm produces incorrect output
首先,这里是节点结构:
struct node{
double data;
node *next, *previous;
};
struct node *first,*last,*current;
现在是排序功能:
void bubblesort(){
bool unfinished = true;
node *temp= current;
current =first;
while(unfinished){
unfinished = false;
while (current!=last){
if (current->data > current->next->data){
temp= current -> next;
current -> next =temp-> next;
temp-> previous = current -> previous;
current -> previous = n;
temp-> next = current;
unfinished = true;
if(current->previous==last)
{last = current;
last->next = NULL;}
if(current==first)
{first= current->previous;
first->previous=NULL;}
}else{
current = current->next;
}
}
};
使用此输入:
69.4637 -> 100.193 -> 136.683 -> 101.736 -> 115.222 -> 138.58 -> 90.3641 -> 101.509 -> 120.108 -> 129.731 -> 95.6236 -> 102.905 -> 89.0621 -> 94.345 -> 98.4529 -> 114.205 -> 129.379 -> 127.703 -> 92.5693 -> 88.4147 -> 125.005 -> 117.251 -> 104.636 -> 90.9676 -> 125.574 -> 134.147 -> 124.374 -> 116.539 -> 108.933 -> 82.3446 -> 124.502 -> 90.4727 -> 92.7035 -> 114.99 -> 114.87 -> 114.692
我只得到这个作为输出:
69.4637 -> 100.193 -> 136.683 -> 138.58
出了什么问题?
current -> previous = n;
应该是:
current -> previous = temp;
相关文章:
- 输出错误,问题是找到总和5000位数字cpp
- 使用复制构造函数的程序输出错误
- 异或字符串加密/解密输出错误
- 在linux上使用g++输出错误,在windows上更正
- 使用递归函数 (c++) 将长字符串转换为整数时输出错误
- ECDSA 密钥对生成输出错误
- fscanf() 输出错误的值
- 输入 1024 后十进制到二进制转换的输出错误?
- 输出错误命令的条件语句
- cuSparse (cusparseDcsrgemm) 中的矩阵乘法输出错误的结果
- 为什么 du -sh 输出错误大小的内存映射文件
- VS2017 的输出错误,但 mingw 有效
- 如何使FFMPEG C 代码不输出错误消息
- 乘以时输出错误.这是我编译器中的错误吗?C
- 输出错误:两个不同编译器上的不同输出:Prime Cryptarithm USACO
- 为什么输出错误崩溃
- C++输入/输出错误
- 尝试用 c++ 制作一个简单的加法器.编译成功,但输出错误
- 当我使用此合并排序代码运行时,输出错误
- 递归功能输出错误的值