int main(){ int data[]={4,6,2,8,5,6,7,0,12,34,39,56,33,11,1,13}; int data2[]={4,6,2,8,5,6,7,0,12,34,39,56,33,11,1,13}; int num=sizeof(data)/sizeof(int); printArray(data,num); sortBubble(data,num); printArray(data,num); sortInsert(data2,num); printArray(data2,num); system("pause"); return 0; }
int main() { big i, n = 100000, A[100000]; srand(time(NULL)); genRandom(A, n); sortBubble(A, n); for (i = 99000; i < 100000; i++) printf("\n%d", A[i]); return 0; }
/* * Главная функция * */ int main() { // Пути к входным/выходным файлам const char * infileName = "H:\\input.txt"; const char * outfileName1 = "H:\\output1.txt"; const char * outfileName2 = "H:\\output2.txt"; const char * outfileName3 = "H:\\output3.txt"; std::cout << "Hello World!" << std::endl; // Приветственное слово std::vector <sort_type> data; // хранилище данных std::cout << "qSort" << std::endl; read(data, infileName); qSort(data); // Быстрая сортировка write(data, outfileName1); std::cout << "sortBubble" << std::endl; read(data, infileName); sortBubble( data); // Сортировка пузырьком write(data, outfileName2); std::cout << "combsort" << std::endl; read(data, infileName); combsort( data); // Сортировка расчёсткой write(data, outfileName3); return 0; }
LightningBolt::LightningBolt(const sf::Vector3f& _Position, const sf::Vector2f& _Destination, const bool& _Branch, const sf::Color& _Color, const float& _Thickness) : Entity(_Position), m_fThickness(_Thickness), m_Color(_Color), m_fAlpha(0.0f), m_bIsDecreasing(false), m_bBranch(_Branch), m_iDrawNumber(0) { m_Sprite = new Sprite(); m_Sprite->setTexture(DATA_MANAGER->getTexture("sfgmk_lightningCorpse")); m_Sprite->setRelativOrigin(0.0f, 0.5f); //Init sf::Vector2f Tangent = _Destination - math::Convert3dTo2d(_Position); sf::Vector2f Normal = math::Calc_UnitVector(sf::Vector2f(Tangent.y, -Tangent.y)); float fLength = math::Calc_Norm(Tangent); m_iPointNumber = (int)(fLength * 0.25f); m_PointArray = new sf::Vector2f[m_iPointNumber]; m_PointArray[0] = sf::Vector2f(_Position.x, _Position.y); m_PointArray[m_iPointNumber - 1] = _Destination; //Position of intermediates points float* fRatioArray = new float[m_iPointNumber - 1]; for( int i(0); i < m_iPointNumber - 2; i++ ) fRatioArray[i] = (float)RAND(0, 100) * 0.01f; fRatioArray[m_iPointNumber - 2] = 0.0f; //Sort the array sortBubble(fRatioArray, (m_iPointNumber - 2) + 1); const float fSway = 80.0f; const float fJaggedness = 1.0f / fSway; float fPreviousDisplacement = 0.0f; for( int i(1); i < m_iPointNumber - 1; i++ ) { float fPos = fRatioArray[i]; float fScale = (fLength * fJaggedness) * (fPos - fRatioArray[i - 1]); //Used to prevent sharp angles by ensuring very close positions also have small perpendicular variation. float envelope = fPos > 0.95f ? 20.0f * (1.0f - fPos) : 1; //Defines an envelope. Points near the middle of the bolt can be further from the central line. float fDisplacement = (float)RAND((int)-fSway, (int)fSway); fDisplacement -= (fDisplacement - fPreviousDisplacement) * (1.0f - fScale); fDisplacement *= envelope; m_PointArray[i] = m_PointArray[0] + (fPos * Tangent) + (fDisplacement * Normal); fPreviousDisplacement = fDisplacement; } delete[] fRatioArray; //TODO Branches /*if( m_bBranch ) { sfgmk::LightningBolt* Branch = NULL; for( int i(1); i < m_iPointNumber - 1; i++ ) { if( RAND(0, 1000) < LIGHTNING_BOLT_BRANCH_CHANCE ) { sf::Vector2f Destination = sfgmk::MatrixRotation22(float(RAND(-30, 30))) * ((m_PointArray[i + 1] - m_PointArray[i]) * float(RAND(1, 100) * 0.01f)); Branch = new sfgmk::LightningBolt(sf::Vector3f(m_PointArray[i].x, m_PointArray[i].y, _Position.z), Destination, 175U, m_bBranch, m_Color, m_fThickness); ADD_ENTITY(Branch); } } }*/ }