c++ 您所在的位置:网站首页 win10explorer基于堆栈的缓冲区溢出 c++

c++

2024-06-16 04:32| 来源: 网络整理| 查看: 265

老实说,我不能告诉你这有什么问题。我读过有类似问题的线程,但人们正在处理内存分配和其他事情,到目前为止,这超出了我作为程序员的范围,而且我的程序几乎没有做这么复杂的事情。

int main() { double input[5] = { 5.0, 6.0, 8.0, 4.3, 5.6 }; GradeBook test(sizeof(input), input); test.bubbleSort(); test.printAll(); return 0; };

这些是我的私有(private)数据成员

const static int gradeBookSize = 6; int classSize; double grades[gradeBookSize]; bool insertionSorted = false; //simply for efficency bool bubbleSorted = false;

我的 GradeBook 类的构造函数

GradeBook(int inputSize, double inputGrades[]) { classSize = inputSize; for (int i = 0; i < classSize; i++) { grades[i] = (inputGrades[i]); } for (int i = classSize; i < sizeof(grades); i++) { grades[i] = 0; } }

最后是我在 main() 方法中实际使用的两个方法

void bubbleSort() { //sorts grades in descending order using bubblesort algorithm bool sorted = false; while (!sorted) { for (int i = 0; i < (sizeof(grades) - 1); i++) { if (grades[i] < grades[i + 1]) { double tmp = grades[i + 1]; grades[i + 1] = grades[i]; grades[i] = tmp; } } bool test = false; for (int i = 0; i < sizeof(grades) - 1; i++) { if (grades[i] < grades[i + 1]) test = true; } sorted = !test; } bubbleSorted = true; insertionSorted = false; } void printAll() { for (int i = 0; i < sizeof(grades); i++) { cout


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有