Fixed up to 6 (including)
This commit is contained in:
9
main.cpp
9
main.cpp
@@ -1,4 +1,4 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "task1.h"
|
#include "task1.h"
|
||||||
#include "task2.h"
|
#include "task2.h"
|
||||||
#include "task3.h"
|
#include "task3.h"
|
||||||
@@ -8,11 +8,11 @@
|
|||||||
#include "task7.h"
|
#include "task7.h"
|
||||||
#include "task8.h"
|
#include "task8.h"
|
||||||
#include "task9.h"
|
#include "task9.h"
|
||||||
#include "task10.h"
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
setlocale(LC_ALL, "Russian");
|
||||||
int id;
|
int id;
|
||||||
bgn:
|
bgn:
|
||||||
cout << "Task id : "; cin >> id;
|
cout << "Task id : "; cin >> id;
|
||||||
@@ -46,11 +46,8 @@ int main()
|
|||||||
case 9:
|
case 9:
|
||||||
task9::init();
|
task9::init();
|
||||||
break;
|
break;
|
||||||
case 10:
|
|
||||||
task10::init();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
goto bgn;
|
goto bgn;
|
||||||
}
|
}
|
||||||
|
|||||||
20
task1.h
20
task1.h
@@ -5,7 +5,7 @@ using namespace std;
|
|||||||
|
|
||||||
namespace task1 {
|
namespace task1 {
|
||||||
|
|
||||||
int F(int num); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
int F(int num); // num table
|
||||||
int a(int* m, int size);
|
int a(int* m, int size);
|
||||||
int b(int* m, int size);
|
int b(int* m, int size);
|
||||||
int v(int* m, int size);
|
int v(int* m, int size);
|
||||||
@@ -18,18 +18,18 @@ namespace task1 {
|
|||||||
cout << "TASK #1" << endl;
|
cout << "TASK #1" << endl;
|
||||||
setlocale(LC_ALL, "Russian");
|
setlocale(LC_ALL, "Russian");
|
||||||
int n;
|
int n;
|
||||||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: "; cin >> n;
|
cout << "Введите длину: "; cin >> n;
|
||||||
|
|
||||||
int* m = new int[n];
|
int* m = new int[n];
|
||||||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>: " << endl;
|
cout << "Введите элементы: " << endl;
|
||||||
for (int i = 0; i < n; i++) { cin >> m[i]; }
|
for (int i = 0; i < n; i++) { cin >> m[i]; }
|
||||||
|
|
||||||
cout << "<EFBFBD>) " << a(m, n) << endl;
|
cout << "а) " << a(m, n) << endl;
|
||||||
cout << "<EFBFBD>) " << b(m, n) << endl;
|
cout << "б) " << b(m, n) << endl;
|
||||||
cout << "<EFBFBD>) " << v(m, n) << endl;
|
cout << "в) " << v(m, n) << endl;
|
||||||
cout << "<EFBFBD>) " << g(m, n) << endl;
|
cout << "г) " << g(m, n) << endl;
|
||||||
cout << "<EFBFBD>) " << d(m, n) << endl;
|
cout << "д) " << d(m, n) << endl;
|
||||||
cout << "<EFBFBD>) " << e(m, n) << endl;
|
cout << "е) " << e(m, n) << endl;
|
||||||
|
|
||||||
delete[] m;
|
delete[] m;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -132,4 +132,4 @@ namespace task1 {
|
|||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
45
task10.h
45
task10.h
@@ -1,45 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <queue>
|
|
||||||
#include <fstream>
|
|
||||||
#include <string>
|
|
||||||
using namespace std;
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace task10 {
|
|
||||||
|
|
||||||
int init()
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
cout << "TASK #9" << endl;
|
|
||||||
setlocale(LC_ALL, "Russian");
|
|
||||||
|
|
||||||
queue<int> dig1;
|
|
||||||
|
|
||||||
ifstream input("C:\\input2.txt");
|
|
||||||
string data;
|
|
||||||
while (getline(input, data))
|
|
||||||
{
|
|
||||||
if (data.size() == 2)
|
|
||||||
{
|
|
||||||
dig2.push(n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!dig1.empty())
|
|
||||||
{
|
|
||||||
cout << dig1.front() << endl;
|
|
||||||
dig1.pop();
|
|
||||||
}
|
|
||||||
while (!dig2.empty())
|
|
||||||
{
|
|
||||||
cout << dig2.front() << endl;
|
|
||||||
dig2.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "<EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>))" << endl;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
8
task2.h
8
task2.h
@@ -9,16 +9,16 @@ namespace task2 {
|
|||||||
cout << "TASK #2" << endl;
|
cout << "TASK #2" << endl;
|
||||||
|
|
||||||
setlocale(LC_ALL, "Russian");
|
setlocale(LC_ALL, "Russian");
|
||||||
int n; cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: "; cin >> n;
|
int n; cout << "Введите размер: "; cin >> n;
|
||||||
int amt = 0, sum = 0;
|
int amt = 0, sum = 0;
|
||||||
int* m = new int[n];
|
int* m = new int[n];
|
||||||
|
|
||||||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>:" << endl;
|
cout << "Введите числа:" << endl;
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
|
|
||||||
int num; cin >> num;
|
int num; cin >> num;
|
||||||
m[i] = num; //<2F><> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>
|
m[i] = num;
|
||||||
if (num % 5 == 0 && num % 7 != 0)
|
if (num % 5 == 0 && num % 7 != 0)
|
||||||
{
|
{
|
||||||
amt++;
|
amt++;
|
||||||
@@ -26,7 +26,7 @@ namespace task2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "<EFBFBD><EFBFBD><EFBFBD>-<2D><>: " << amt << endl << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " << sum;
|
cout << "Кол-во: " << amt << endl << "Сумма: " << sum;
|
||||||
|
|
||||||
delete[] m;
|
delete[] m;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
12
task3.h
12
task3.h
@@ -11,10 +11,10 @@ namespace task3 {
|
|||||||
cout << "TASK #3" << endl;
|
cout << "TASK #3" << endl;
|
||||||
|
|
||||||
setlocale(LC_ALL, "Russian");
|
setlocale(LC_ALL, "Russian");
|
||||||
int n; cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: "; cin >> n;
|
int n; cout << "Введите длину: "; cin >> n;
|
||||||
int amt = 0;
|
int amt = 0;
|
||||||
int* m = new int[n];
|
int* m = new int[n];
|
||||||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>: " << endl;
|
cout << "Введите числа: " << endl;
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
cin>>m[i];
|
cin>>m[i];
|
||||||
@@ -27,12 +27,10 @@ namespace task3 {
|
|||||||
max = cur > max ? cur : max;
|
max = cur > max ? cur : max;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " << max * (max!=1) << " <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>\n";
|
cout << "а) " << (max >= 2) << endl;
|
||||||
cout << "<EFBFBD>) " << (max >= 2) << endl;
|
cout << "б) " << (max >= 3) << endl;
|
||||||
cout << "<EFBFBD>) " << (max >= 3) << endl;
|
|
||||||
|
|
||||||
delete[] m;
|
delete[] m;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|||||||
14
task4.h
14
task4.h
@@ -1,6 +1,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace task4 {
|
namespace task4 {
|
||||||
|
|
||||||
struct Node
|
struct Node
|
||||||
@@ -10,17 +12,17 @@ namespace task4 {
|
|||||||
Node* next;
|
Node* next;
|
||||||
};
|
};
|
||||||
|
|
||||||
Node* newNode(int key); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
Node* newNode(int key);
|
||||||
Node* list(int size, bool print); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
Node* list(int size, bool print);
|
||||||
int sum(Node* head); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
int sum(Node* head);
|
||||||
|
|
||||||
int init()
|
int init()
|
||||||
{
|
{
|
||||||
setlocale(LC_ALL, "Russian");
|
setlocale(LC_ALL, "Russian");
|
||||||
int n; cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: "; cin >> n;
|
int n; cout << "Введите длину: "; cin >> n;
|
||||||
|
|
||||||
Node* array = list(n, true);
|
Node* array = list(n, true);
|
||||||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " << sum(array);
|
cout << "Сумма: " << sum(array);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -66,4 +68,4 @@ namespace task4 {
|
|||||||
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
task5.h
8
task5.h
@@ -9,9 +9,9 @@ namespace task5 {
|
|||||||
cout << "TASK #5" << endl;
|
cout << "TASK #5" << endl;
|
||||||
setlocale(LC_ALL, "Russian");
|
setlocale(LC_ALL, "Russian");
|
||||||
|
|
||||||
int n; cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: "; cin >> n;
|
int n; cout << "Ввелите длину: "; cin >> n;
|
||||||
double* m = new double[n];
|
double* m = new double[n];
|
||||||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>:" << endl;
|
cout << "Введите элементы:" << endl;
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
cin >> m[i];
|
cin >> m[i];
|
||||||
@@ -23,14 +23,14 @@ namespace task5 {
|
|||||||
double num = m[i];
|
double num = m[i];
|
||||||
if (num > min)
|
if (num > min)
|
||||||
{
|
{
|
||||||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. " << endl;
|
cout << "Массив не упорядочен по убыванию. " << endl;
|
||||||
delete[] m;
|
delete[] m;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
min = num;
|
min = num;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. " << endl;
|
cout << "Массив упорядочен по убыванию. " << endl;
|
||||||
delete[] m;
|
delete[] m;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
52
task6.h
52
task6.h
@@ -1,4 +1,4 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@@ -11,52 +11,50 @@ namespace task6 {
|
|||||||
Node* next;
|
Node* next;
|
||||||
};
|
};
|
||||||
|
|
||||||
Node* newNode(int key); //создает узел
|
Node* newNode(int key);
|
||||||
Node* rand_list(int size); //создает список
|
Node* rand_list(int size);
|
||||||
void print_list(Node* head); //пишет элементы списка
|
void print_list(Node* head);
|
||||||
|
|
||||||
bool is_list_empty(Node* head); //пишет, что список пуст, если подкинуть nullptr
|
bool is_list_empty(Node* head);
|
||||||
void push_back(Node* head, int key); //поместить в конец
|
void push_back(Node* head, int key);
|
||||||
void push_forward(Node*& head, int key); //поместить в начало
|
void push_forward(Node*& head, int key);
|
||||||
void squeeze_in(Node* head, int pos, int key); //"всунуть" после элемента
|
void squeeze_in(Node* head, int pos, int key);
|
||||||
|
|
||||||
int list_size(Node* head); //узнать размер списка
|
int list_size(Node* head);
|
||||||
void behead(Node*& head); //получить список без первого элемента
|
void behead(Node*& head);
|
||||||
|
|
||||||
int init()
|
int init()
|
||||||
{
|
{
|
||||||
setlocale(LC_ALL, "Russian");
|
setlocale(LC_ALL, "Russian");
|
||||||
int n; cout << "Введите размер: "; cin >> n;
|
int n; cout << "Введите длину: "; cin >> n;
|
||||||
Node* lst = rand_list(n);
|
Node* lst = rand_list(n);
|
||||||
|
|
||||||
if (is_list_empty(lst))
|
if (is_list_empty(lst))
|
||||||
{
|
{
|
||||||
cout << "Список является пустым." << endl;
|
cout << "Список пуст." << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
cout << "Список содержит элементы: " << endl;
|
cout << "Список: " << endl;
|
||||||
print_list(lst);
|
print_list(lst);
|
||||||
|
|
||||||
cout << "\n\nДобавим элемент 11111 в начало:" << endl;
|
cout << "Добавим в начало 11111:" << endl;
|
||||||
push_forward(lst, 11111);
|
push_forward(lst, 11111);
|
||||||
print_list(lst);
|
print_list(lst);
|
||||||
|
|
||||||
cout << "\n\nДобавим элемент 22222 в конец:" << endl;
|
cout << "Добавим в конец 22222:" << endl;
|
||||||
push_back(lst, 22222);
|
push_back(lst, 22222);
|
||||||
print_list(lst);
|
print_list(lst);
|
||||||
|
|
||||||
cout << "\n\nДобавим элемент 33333 где-то в середине:" << endl;
|
cout << "Добавим в середину 33333:" << endl;
|
||||||
squeeze_in(lst, n/2+1, 33333);
|
squeeze_in(lst, n/2+1, 33333);
|
||||||
print_list(lst);
|
print_list(lst);
|
||||||
|
|
||||||
cout << "\n\nВсего элементов сейчас: " << list_size(lst) << endl;
|
cout << "Длина списка: " << list_size(lst) << endl;
|
||||||
|
|
||||||
cout << "\n\nПолучим список без первого элемента с помощью функции обезглавливания:" << endl;
|
cout << "Список без первого элемента:" << endl;
|
||||||
behead(lst);
|
behead(lst);
|
||||||
print_list(lst);
|
print_list(lst);
|
||||||
|
|
||||||
cout << "\n\nДа это жоско";
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,18 +156,6 @@ namespace task6 {
|
|||||||
|
|
||||||
void behead(Node*& head)
|
void behead(Node*& head)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
⢿⣿⣿⣿⣭⠹⠛⠛⠛⢿⣿⣿⣿⣿⡿⣿⠷⠶⠿⢻⣿⣛⣦⣙⠻⣿
|
|
||||||
⣿⣿⢿⣿⠏⠀⠀⡀⠀⠈⣿⢛⣽⣜⠯⣽⠀⠀⠀⠀⠙⢿⣷⣻⡀⢿
|
|
||||||
⠐⠛⢿⣾⣖⣤⡀⠀⢀⡰⠿⢷⣶⣿⡇⠻⣖⣒⣒⣶⣿⣿⡟⢙⣶⣮
|
|
||||||
⣤⠀⠀⠛⠻⠗⠿⠿⣯⡆⣿⣛⣿⡿⠿⠮⡶⠼⠟⠙⠊⠁⠀⠸⢣⣿
|
|
||||||
⣿⣷⡀⠀⠀⠀⠀⠠⠭⣍⡉⢩⣥⡤⠥⣤⡶⣒⠀⠀⠀⠀⠀⢰⣿⣿
|
|
||||||
⣿⣿⡽⡄⠀⠀⠀⢿⣿⣆⣿⣧⢡⣾⣿⡇⣾⣿⡇⠀⠀⠀⠀⣿⡇⠃
|
|
||||||
⣿⣿⣷⣻⣆⢄⠀⠈⠉⠉⠛⠛⠘⠛⠛⠛⠙⠛⠁⠀⠀⠀⠀⣿⡇⢸
|
|
||||||
⢞⣿⣿⣷⣝⣷⣝⠦⡀⠀⠀⠀⠀⠀⠀⠀⡀⢀⠀⠀⠀⠀⠀⠛⣿⠈
|
|
||||||
⣦⡑⠛⣟⢿⡿⣿⣷⣝⢧⡀⠀⠀⣶⣸⡇⣿⢸⣧⠀⠀⠀⠀⢸⡿⡆
|
|
||||||
⣿⣿⣷⣮⣭⣍⡛⠻⢿⣷⠿⣶⣶⣬⣬⣁⣉⣀⣀⣁⡤⢴⣺⣾⣽⡇
|
|
||||||
*/
|
|
||||||
head = head->next;
|
head = head->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
84
task7.h
84
task7.h
@@ -1,4 +1,4 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -13,46 +13,46 @@ namespace task7 {
|
|||||||
Node* next;
|
Node* next;
|
||||||
};
|
};
|
||||||
|
|
||||||
Node* newNode(int key); //создает узел
|
Node* newNode(int key);
|
||||||
Node* rand_list(int size); //создает список
|
Node* rand_list(int size);
|
||||||
void print_list(Node* head); //пишет элементы списка
|
void print_list(Node* head);
|
||||||
|
|
||||||
bool is_list_empty(Node* head); //пишет, что список пуст, если подкинуть nullptr
|
bool is_list_empty(Node* head);
|
||||||
void push_back(Node* head, int key); //поместить в конец
|
void push_back(Node* head, int key);
|
||||||
void push_forward(Node*& head, int key); //поместить в начало
|
void push_forward(Node*& head, int key);
|
||||||
void squeeze_in(Node* head, int pos, int key); //"всунуть" после элемента
|
void squeeze_in(Node* head, int pos, int key);
|
||||||
void behead(Node*& head);
|
void behead(Node*& head);
|
||||||
int list_size(Node* head); //узнать размер списка
|
int list_size(Node* head);
|
||||||
|
|
||||||
bool equal(Node* head1, Node* head2); //сравнивает списки
|
bool equal(Node* head1, Node* head2);
|
||||||
bool all_in(Node* head1, Node* head2); //проверяет, есть ли все элементы первого списка в другом
|
bool all_in(Node* head1, Node* head2);
|
||||||
bool dupes_present(Node* head); //проверка на дубликаты
|
bool dupes_present(Node* head);
|
||||||
void head_to_end(Node*& head); //перемещает первый элемент в конец
|
void head_to_end(Node*& head);
|
||||||
void end_to_head(Node*& head); //перемещает последний элемент в начало
|
void end_to_head(Node*& head);
|
||||||
void merge(Node* head1, Node* head2); //переносит элементы списка 2 в конец списка 1
|
void merge(Node* head1, Node* head2);
|
||||||
void reversed(Node*& head); //возвращает элементы массива в обрат. порядке
|
void reversed(Node*& head);
|
||||||
bool in_list(Node* head, int key); //ДЛЯ ЗАДАНИЯ ПОД БУКВОЙ З). Определяет, есть ли элемент в списке
|
bool in_list(Node* head, int key);
|
||||||
void remove_dupes(Node*& head); //not implemented
|
void remove_dupes(Node*& head); // not implemented
|
||||||
|
|
||||||
int init()
|
int init()
|
||||||
{
|
{
|
||||||
cout << "TASK #7" << endl;
|
cout << "TASK #7" << endl;
|
||||||
setlocale(LC_ALL, "Russian");
|
setlocale(LC_ALL, "Russian");
|
||||||
|
|
||||||
cout << "В конце задания 6 ничего не предвещало беды\n";
|
cout << "РконÑе Ð·Ð°Ð´Ð°Ð½Ð¸Ñ 6 ниÑего не пÑедвеÑало бедÑ\n";
|
||||||
|
|
||||||
int n1; cout << "Введите размер списка 1: "; cin >> n1;
|
int n1; cout << "ÐведиÑе ÑÐ°Ð·Ð¼ÐµÑ ÑпиÑка 1: "; cin >> n1;
|
||||||
Node* lst1 = newNode(0);
|
Node* lst1 = newNode(0);
|
||||||
cout << "Введите числа:" << endl;
|
cout << "ÐведиÑе ÑиÑла:" << endl;
|
||||||
for (int i = 0; i < n1; i++)
|
for (int i = 0; i < n1; i++)
|
||||||
{
|
{
|
||||||
int num; cin >> num;
|
int num; cin >> num;
|
||||||
push_back(lst1, num);
|
push_back(lst1, num);
|
||||||
}
|
}
|
||||||
|
|
||||||
int n2; cout << "Введите размер списка 2: "; cin >> n2;
|
int n2; cout << "ÐведиÑе ÑÐ°Ð·Ð¼ÐµÑ ÑпиÑка 2: "; cin >> n2;
|
||||||
Node* lst2 = newNode(0);
|
Node* lst2 = newNode(0);
|
||||||
cout << "Введите числа:" << endl;
|
cout << "ÐведиÑе ÑиÑла:" << endl;
|
||||||
for (int i = 0; i < n2; i++)
|
for (int i = 0; i < n2; i++)
|
||||||
{
|
{
|
||||||
int num; cin >> num;
|
int num; cin >> num;
|
||||||
@@ -60,61 +60,61 @@ namespace task7 {
|
|||||||
}
|
}
|
||||||
behead(lst1);
|
behead(lst1);
|
||||||
behead(lst2);
|
behead(lst2);
|
||||||
cout << "\n\nИмеем два списка: \n";
|
cout << "\n\nÐмеем два ÑпиÑка: \n";
|
||||||
print_list(lst1);
|
print_list(lst1);
|
||||||
print_list(lst2);
|
print_list(lst2);
|
||||||
cout << "\n\n";
|
cout << "\n\n";
|
||||||
|
|
||||||
if (equal(lst1, lst2))
|
if (equal(lst1, lst2))
|
||||||
{
|
{
|
||||||
cout << "Списки совпадают";
|
cout << "СпиÑки ÑовпадаÑÑ";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout << "Списки не равны";
|
cout << "СпиÑки не ÑавнÑ";
|
||||||
}
|
}
|
||||||
cout << "\n\n";
|
cout << "\n\n";
|
||||||
|
|
||||||
if (all_in(lst1, lst2))
|
if (all_in(lst1, lst2))
|
||||||
{
|
{
|
||||||
cout << "Все элементы первого списка есть во втором";
|
cout << "ÐÑе ÑлеменÑÑ Ð¿ÐµÑвого ÑпиÑка еÑÑÑ Ð²Ð¾ вÑоÑом";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout << "Первый список имеет элементы, которых нет во втором";
|
cout << "ÐеÑвÑй ÑпиÑок Ð¸Ð¼ÐµÐµÑ ÑлеменÑÑ, коÑоÑÑÑ
Ð½ÐµÑ Ð²Ð¾ вÑоÑом";
|
||||||
}
|
}
|
||||||
cout << "\n\n";
|
cout << "\n\n";
|
||||||
|
|
||||||
if (dupes_present(lst1))
|
if (dupes_present(lst1))
|
||||||
{
|
{
|
||||||
cout << "В списке есть дубликаты";
|
cout << "Ð ÑпиÑке еÑÑÑ Ð´ÑбликаÑÑ";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout << "В списке нет дубликатов";
|
cout << "Ð ÑпиÑке Ð½ÐµÑ Ð´ÑбликаÑов";
|
||||||
}
|
}
|
||||||
cout << "\n\n";
|
cout << "\n\n";
|
||||||
print_list(lst1);
|
print_list(lst1);
|
||||||
cout << "Перенесем первый элемент списка 1 в конец : \n";
|
cout << "ÐеÑенеÑем пеÑвÑй ÑÐ»ÐµÐ¼ÐµÐ½Ñ ÑпиÑка 1 в ÐºÐ¾Ð½ÐµÑ : \n";
|
||||||
head_to_end(lst1);
|
head_to_end(lst1);
|
||||||
print_list(lst1);
|
print_list(lst1);
|
||||||
|
|
||||||
cout << "\n\n";
|
cout << "\n\n";
|
||||||
print_list(lst2);
|
print_list(lst2);
|
||||||
cout << "Перенесем последний элемент списка 2 в начало : \n";
|
cout << "ÐеÑенеÑем поÑледний ÑÐ»ÐµÐ¼ÐµÐ½Ñ ÑпиÑка 2 в наÑало : \n";
|
||||||
end_to_head(lst2);
|
end_to_head(lst2);
|
||||||
print_list(lst2);
|
print_list(lst2);
|
||||||
|
|
||||||
cout << "\n\n";
|
cout << "\n\n";
|
||||||
print_list(lst1);
|
print_list(lst1);
|
||||||
print_list(lst2);
|
print_list(lst2);
|
||||||
cout << "Соединим два списка: \n";
|
cout << "Соединим два ÑпиÑка: \n";
|
||||||
merge(lst1, lst2);
|
merge(lst1, lst2);
|
||||||
print_list(lst1);
|
print_list(lst1);
|
||||||
cout << "Развернем список: \n";
|
cout << "РазвеÑнем ÑпиÑок: \n";
|
||||||
reversed(lst1);
|
reversed(lst1);
|
||||||
print_list(lst1);
|
print_list(lst1);
|
||||||
cout << "Удалим дубликаты из списка: \n";
|
cout << "Удалим дÑбликаÑÑ Ð¸Ð· ÑпиÑка: \n";
|
||||||
remove_dupes(lst1);
|
remove_dupes(lst1);
|
||||||
print_list(lst1);
|
print_list(lst1);
|
||||||
|
|
||||||
@@ -204,18 +204,6 @@ namespace task7 {
|
|||||||
|
|
||||||
void behead(Node*& head)
|
void behead(Node*& head)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
⢿⣿⣿⣿⣭⠹⠛⠛⠛⢿⣿⣿⣿⣿⡿⣿⠷⠶⠿⢻⣿⣛⣦⣙⠻⣿
|
|
||||||
⣿⣿⢿⣿⠏⠀⠀⡀⠀⠈⣿⢛⣽⣜⠯⣽⠀⠀⠀⠀⠙⢿⣷⣻⡀⢿
|
|
||||||
⠐⠛⢿⣾⣖⣤⡀⠀⢀⡰⠿⢷⣶⣿⡇⠻⣖⣒⣒⣶⣿⣿⡟⢙⣶⣮
|
|
||||||
⣤⠀⠀⠛⠻⠗⠿⠿⣯⡆⣿⣛⣿⡿⠿⠮⡶⠼⠟⠙⠊⠁⠀⠸⢣⣿
|
|
||||||
⣿⣷⡀⠀⠀⠀⠀⠠⠭⣍⡉⢩⣥⡤⠥⣤⡶⣒⠀⠀⠀⠀⠀⢰⣿⣿
|
|
||||||
⣿⣿⡽⡄⠀⠀⠀⢿⣿⣆⣿⣧⢡⣾⣿⡇⣾⣿⡇⠀⠀⠀⠀⣿⡇⠃
|
|
||||||
⣿⣿⣷⣻⣆⢄⠀⠈⠉⠉⠛⠛⠘⠛⠛⠛⠙⠛⠁⠀⠀⠀⠀⣿⡇⢸
|
|
||||||
⢞⣿⣿⣷⣝⣷⣝⠦⡀⠀⠀⠀⠀⠀⠀⠀⡀⢀⠀⠀⠀⠀⠀⠛⣿⠈
|
|
||||||
⣦⡑⠛⣟⢿⡿⣿⣷⣝⢧⡀⠀⠀⣶⣸⡇⣿⢸⣧⠀⠀⠀⠀⢸⡿⡆
|
|
||||||
⣿⣿⣷⣮⣭⣍⡛⠻⢿⣷⠿⣶⣶⣬⣬⣁⣉⣀⣀⣁⡤⢴⣺⣾⣽⡇
|
|
||||||
*/
|
|
||||||
Node* _head = head;
|
Node* _head = head;
|
||||||
head=head->next;
|
head=head->next;
|
||||||
delete _head;
|
delete _head;
|
||||||
@@ -393,4 +381,4 @@ namespace task7 {
|
|||||||
}
|
}
|
||||||
head = result;
|
head = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
task8.h
10
task8.h
@@ -12,10 +12,10 @@ namespace task8 {
|
|||||||
Node* next;
|
Node* next;
|
||||||
};
|
};
|
||||||
|
|
||||||
Node* newNode(int key); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
Node* newNode(int key);
|
||||||
Node* rand_list(int size); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
Node* rand_list(int size);
|
||||||
void print_list(Node* head); //<2F><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
void print_list(Node* head);
|
||||||
void cycle(Node*&head, int offset); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
void cycle(Node*&head, int offset);
|
||||||
|
|
||||||
int init()
|
int init()
|
||||||
{
|
{
|
||||||
@@ -111,4 +111,4 @@ namespace task8 {
|
|||||||
prv->next = nullptr;
|
prv->next = nullptr;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user