NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <iostream>
#include <fstream>

struct type
{
char data;
int key;
};

// сортировка пузырьком
void bubbleSort(type *arr, int n)
{
type p;
int i, j;
for(i = 0; i < n-1; i++)
{
p = arr[j];
while(arr[j].key < arr[j+1].key && j >= 0) // меняем знак в 1 неравенстве для смены нужного порядка
{
p = arr[j];
arr[j] = arr[j+1];
arr[j+1] = p;
j--;
}
}
}

// улучшенная сортировка пузырьком (шейкер сортировка)
void shakerSort(type *arr, int n)
{
int left = 0;
int right = n-1;
int i, j;
while(left < right)
{
for(i = left; i < right; i++)
{
if (arr[i].key > arr[i+1].key)
{
type p = arr[i];
arr[i] = arr[i+1];
arr[i+1] = p;
}
right--;
for(i = right; i > left; i--)
{
type p = arr[i];
arr[i] = arr[i-1];
arr[i-1] = p;
}
left++;
}
}
}

// сортировка простыми вставками
void insertionSort(type *arr, int n)
{
type p;
int i, j;
for(i = 1; i < n; i++)
{
p = arr[i];
j = i - 1;
while(arr[j].key > p.key && j >= 0) // меняем знак в 1 неравенстве для смены нужного порядка
{
arr[j+1] = arr[j];
j--;
}
arr[j+1] = p;
}
}

// сорировка просыми выборами
void selectionSort(type *arr, int n)
{
int i, j, k;
type *p;
for(i = 0; i < n-1; i++)
{
k = i;
for(j = i+1; j < n; j++)
{
if(arr[k].key < arr[j].key)
{
p = arr[k];
arr[k] = arr[j];
arr[j] = p;
}
}
}
}

// сортировка Шелла
void shellSort(type *arr, int n)
{
int i, j, interval;
for(interval = n/2; interval > 0; interval /= 2)
{
for(i = interval; i < n; i++)
{
type p = arr[i];
for(j = i; j >= interval && p[j-interval].key > p.key; j -= interval)
{
arr[j] = arr[j-interval];
}
arr[j] = p;
}
}
}

// быстрая сортировка (сортировка Хоара)
void quickSort(type *arr, int low, int high)
{
int i = low;
int j = high;
type pivot = arr[(i+j)/2];
type p;

while (i <= j)
{
while (arr[i].key < pivot.key)
{
i++;
}
while (arr[j].key > pivot.key)
{
j--;
}
if (i <= j)
{
p = arr[i];
arr[i] = arr[j];
arr[j] = p;
i++;
j--;
}
}
if (j > low)
{
quickSort(arr, low, j);
}
if (i < high)
{
quickSort(arr, i, high);
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.