- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
<分区>
我得到的输出:
我不知道这个 -33686019 数字是从哪里来的。我已经发布了所有代码,因为我真的不知道是什么导致了它。
冒泡排序:
#include "Sorting.h"
double Sorting::bubbleSort( int size )
{
//Make a copy of our "master key" array for us to sort
int *toSort = whichArray(size);
int *theArray = copyArray( toSort, size );
double time;
cout << "The base array" << endl;
for(int i = 0; i < 10; i++ )
{
cout << theArray[i] << endl;
}
//The sort
//Begin time
timer.startClock();
bool swapped = true;
int temp = 0;
while( swapped == true )
{
swapped = false;
for( int i = 0; i < size; i++ )
{
if( theArray[i+1] < theArray[i] )
{
/*temp = theArray[i+1];
theArray[i+1] = theArray[i];
theArray[i] = temp;*/
swap(theArray[i + 1], theArray[i]);
swapped = true;
}
}
}
time = timer.getTime();
cout << "The Sorted array" << endl;
for(int x = 0; x < 10; x++ )
{
cout << theArray[x] << endl;
}
return time;
}
排序类:
#ifndef SORTING_H
#define SORTING_H
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//^For random numbers
#include <iostream>
#include "TimerSystem.h"
#include <iomanip>
using namespace std;
class Sorting
{
private:
//The below pointers will point to arrays that hold the data sets
int *n10;
int *n100;
int *n1000;
int *n10000;
TimerSystem timer;
double runs[4][4];
public:
Sorting();
~Sorting(){};
//Testing functions
void printArray();
void print2DArray();
void dryRun();
//Data manging and creating
int randomNumGen();
int* arrayGen( int size );//Returning a pointer
int* copyArray( int *toCopy, int size );//Makes an array that the program can sort. The leaves the original array intact
int* whichArray( int size );
void datasetRun( int whichSort );//Does three runs of a sort and gets the average for all 4 array sizes
//Sorts
double bubbleSort( int size );
};
#endif
其他调用函数:
#include "Sorting.h"
int Sorting::randomNumGen()
{
int randomNumber = rand() % 10000 + 1;
if( randomNumber > 10000 || randomNumber < 0 )
{
system("pause");
}
return randomNumber;
}
int* Sorting::arrayGen( int size )
{
int *theArray= new int[size];
for( int i = 0; i < size; i++ )
{
theArray[i] = randomNumGen();
}
return theArray;
}
int* Sorting::copyArray( int *toCopy, int size )
{
int *newArray = new int[size];
for( int i = 0; i < size; i++ )
{
newArray[i] = toCopy[i];
}
return newArray;
}
int* Sorting::whichArray( int size )
{
if( size == 10 )
{
return n10;
}
else if( size == 100 )
{
return n100;
}
else if( size == 1000 )
{
return n100;
}
else if( size == 10000 )
{
return n1000;
}
return NULL;
}
void Sorting::datasetRun( int whichSort )
{
//1: Bubble
//2: Insertion
//3: Selection
//4: Shell
//5: Quick
//6: Merge
int col = 0;
int row = 0;
int set = 10;
bool runDone = false;
if( whichSort == 1 )
{
for( int row = 0; row < 4; row++ )
{
for( int col = 0; col < 4; col++ )
{
runs[row][col] = bubbleSort( set );
}
//set = set * 10;
}
}
}
//Constructor
Sorting::Sorting()
{
//For the random number generator
srand( time(NULL) );
n10 = arrayGen( 10 );
n100 = arrayGen( 100 );
n1000 = arrayGen( 1000 );
n10000 = arrayGen( 10000 );
}
//Functions for testing
void Sorting::printArray()
{
int size = 10000;
for( int i = 0; i < size; i++ )
{
cout << n10000[i] << " ";
}
}
void Sorting::print2DArray()
{
for( int height = 0; height < 4; height++ )
{
for( int width = 0; width < 4; width++ )
{
cout << runs[height][width] << endl;
}
cout << "\n\n";
}
}
主要功能:
#include "Sorting.h"
void main()
{
//Makes the numbers easily readable
cout.setf(ios::fixed | ios::showpoint);
cout.precision(16);
Sorting theSorting;
//theSorting.printArray();
//cout << theSorting.bubbleSort( 10 ) << endl;
//theSorting.datasetRun(1);
//theSorting.print2DArray();
theSorting.bubbleSort( 10 );
system("pause");
}
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 7 年前。 Improve t
我正在处理 SQL 和用户输入。因此,我使用 glue 库来处理参数化查询。 但是,为了保持简洁,我将所有内容包装在一个函数中: safeQuery SELECT * FROM foo WHERE
我的拓扑是这样的:kafka(p:6)->reduce(p:6)->db writer(p:12)(其中p:是并行)。 我让它在单个节点“集群”上运行 taskmanager.numberOfTask
我有一个 Singleton 类,我试图用它来存储从 Internet 下载的图像,以便我可以随时访问它。工作流程是我登录到 Facebook,并将图像下载到 Singleton 类。一切都很好,它显
首先,这是我的声明和初始化: int** GameField = 0; GameField = new int*[mapsize]; for(int i = 0; i
我正在使用 pthreads 编写一个多线程演示程序,其中一个线程将数据加载到 STL 队列中,另一个线程从中读取数据。听起来微不足道,对吧?不幸的是,插入队列的数据正在消失。我对多线程并不陌生,也不
我有一个函数 (GetArgs) 使用可变参数模板对它的参数(每个指针)进行排序,将每个参数发送到另一个函数 (GetArg),该函数已为每种类型重载(目前是整数和 float )。每种类型的重载函数
我成功地使用蓝牙连接了 iPhone 和 Mac。 iPhone 是核心,Mac 是外围设备。连接后,两者都可以通信(iPhone 正在订阅一些特征,由 Mac 宣传)。 但是,经过一段时间(随机?)
这是一个足够简单的问题,令我感到惊讶的是,我找不到任何对之前问过它的人的引用。和this不一样,也不受 this discussion 的保护. 我有一个 4-d 矩阵(尺寸为 16x10x15x39
我正在使用两个组件,并且我正在使用这种模式:子组件应尽可能保持隔离 - 它正在处理自己的验证错误。父组件应该检查子组件之间存在依赖关系的错误。因此,就我而言:密码字段和密码确认字段。 这是我的代码
我有一个应用程序,用户可以通过两种方式浏览 map (例如缩略图和列表中的 map ) /map/browse /map/list 现在,我想将这些 View 限制为仅显示特定用户的 map ,例如通
我有这种类型和这些功能: data Tag a where Tag :: (Show a, Eq a, Ord a, Storable a, Binary a) => a -> BL.Byte
我写了一个非常简单的 Flink 流作业,它使用 FlinkKafkaConsumer082 从 Kafka 获取数据。 protected DataStream getKafkaStream(Str
几天前我不小心删除了我的.bashrc。我尝试重新创建它,但不幸的是我仍然遇到一些问题。我以前使用的 Java 调试器不再正常工作,因为它找不到这个类: aetherboard:Home shwang
我正在尝试序列化/反序列化以下内容 @JsonTypeInfo(use = JsonTypeInfo.Id.NAME) @JsonSubTypes({ @JsonSubTypes.Type(v
我目前正在编写一个非常小的Java程序来实现一次性pad,其中pad(或 key )本身是使用SecureRandom对象生成为一系列字节的,该对象使用一个简单的字符串进行播种SHA-512 算法。
您可以通过在物理设备上下载并运行此代码来重现错误:https://github.com/Hoya/RCCPeakableImageView 它所做的是通过 UIImageView 子类向图像添加视差效
我在使用 google analytis 时遇到了一些问题。我们有一个网站,用户可以在登陆页面上填写个人信息(姓名、地址、电子邮件等)。该网站位于http://link.提交表单后,用户将被定向到 h
我正在创建一个可以使用键盘控件旋转的 3D 立方体。但是在旋转之后,每张脸的部分失去了交互性(鼠标事件不会在包含的元素上注册)。任何人都知道可能导致该问题的原因是什么? 这很难解释,所以这里有一个测试
我今天在调试 SWIG 类型映射时遇到了一个有趣的问题。任何人都想告诉我为什么 Visual C++ 2008 在从 ourLib::Char * 转换为 const ourLib::Char * &
我是一名优秀的程序员,十分优秀!