/
Krahjotdaan
/
ArrayModule-for-cpp
Обзор
Документация
Войти
/
Krahjotdaan
/
ArrayModule-for-cpp
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
implementation_files/replace_by_value.cpp
156 строк
5 KB
Ostapenko
Fix: default parameters of erase_by_value, fill and replace_by_value functions moved to header file
14 июн 2023, 21:39
14 июн 2023, 21:39
7a3b338
Код
Авторство
О чём код?
#include "../arraymodule.hpp" #include <iostream> using namespace std; /// @brief replacing element by its value and occurrence /// @param array source array /// @param size size of array /// @param source_value value of replaced element /// @param replaced_value source_value is replaced by replaced_value /// @param occurrence occurrence of replaced element, by default 1 void replace_by_value(int array[], int size, int source_value, int replaced_value, int occurrence) { int s = 0; for (int i = 0; i < size; i++) { if (array[i] == source_value) { s++; if (occurrence == s) { array[i] = replaced_value; break; } } } } /// @brief replacing element by its value and occurrence /// @param array source array /// @param size size of array /// @param source_value value of replaced element /// @param replaced_value source_value is replaced by replaced_value /// @param occurrence occurrence of replaced element, by default 1 void replace_by_value(long long array[], int size, long long source_value, long long replaced_value, int occurrence) { int s = 0; for (int i = 0; i < size; i++) { if (array[i] == source_value) { s++; if (occurrence == s) { array[i] = replaced_value; break; } } } } /// @brief replacing element by its value and occurrence /// @param array source array /// @param size size of array /// @param source_value value of replaced element /// @param replaced_value source_value is replaced by replaced_value /// @param occurrence occurrence of replaced element, by default 1 void replace_by_value(float array[], int size, float source_value, float replaced_value, int occurrence) { int s = 0; for (int i = 0; i < size; i++) { if (array[i] == source_value) { s++; if (occurrence == s) { array[i] = replaced_value; break; } } } } /// @brief replacing element by its value and occurrence /// @param array source array /// @param size size of array /// @param source_value value of replaced element /// @param replaced_value source_value is replaced by replaced_value /// @param occurrence occurrence of replaced element, by default 1 void replace_by_value(double array[], int size, double source_value, double replaced_value, int occurrence) { int s = 0; for (int i = 0; i < size; i++) { if (array[i] == source_value) { s++; if (occurrence == s) { array[i] = replaced_value; break; } } } } /// @brief replacing element by its value and occurrence /// @param array source array /// @param size size of array /// @param source_value value of replaced element /// @param replaced_value source_value is replaced by replaced_value /// @param occurrence occurrence of replaced element, by default 1 void replace_by_value(int array[], long long size, int source_value, int replaced_value, long long occurrence) { long long s = 0; for (long long i = 0; i < size; i++) { if (array[i] == source_value) { s++; if (occurrence == s) { array[i] = replaced_value; break; } } } } /// @brief replacing element by its value and occurrence /// @param array source array /// @param size size of array /// @param source_value value of replaced element /// @param replaced_value source_value is replaced by replaced_value /// @param occurrence occurrence of replaced element, by default 1 void replace_by_value(long long array[], long long size, long long source_value, long long replaced_value, long long occurrence) { long long s = 0; for (long long i = 0; i < size; i++) { if (array[i] == source_value) { s++; if (occurrence == s) { array[i] = replaced_value; break; } } } } /// @brief replacing element by its value and occurrence /// @param array source array /// @param size size of array /// @param source_value value of replaced element /// @param replaced_value source_value is replaced by replaced_value /// @param occurrence occurrence of replaced element, by default 1 void replace_by_value(float array[], long long size, float source_value, float replaced_value, long long occurrence) { long long s = 0; for (long long i = 0; i < size; i++) { if (array[i] == source_value) { s++; if (occurrence == s) { array[i] = replaced_value; break; } } } } /// @brief replacing element by its value and occurrence /// @param array source array /// @param size size of array /// @param source_value value of replaced element /// @param replaced_value source_value is replaced by replaced_value /// @param occurrence occurrence of replaced element, by default 1 void replace_by_value(double array[], long long size, double source_value, double replaced_value, long long occurrence) { long long s = 0; for (long long i = 0; i < size; i++) { if (array[i] == source_value) { s++; if (occurrence == s) { array[i] = replaced_value; break; } } } }