Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cf6becd
task_03
pogodaevala Mar 1, 2025
3fbabbc
topic3 question1-2-3 theory
pogodaevala Mar 15, 2025
6024697
topic3 question1-2-3 theory better
pogodaevala Mar 15, 2025
476444e
README.md changes
pogodaevala Mar 15, 2025
c8bb5ea
question4-5-6.md theory
pogodaevala Mar 15, 2025
8a93757
question4-5-6.md better
pogodaevala Mar 15, 2025
4a73676
README.md changes
pogodaevala Mar 15, 2025
165d1f5
question1-2-3.md and question4-5-6.md theory
pogodaevala Mar 15, 2025
e78dc8d
quick_sort?
pogodaevala Mar 15, 2025
9aa106b
tests for stack and fix stack
pogodaevala Mar 17, 2025
7b9f0f4
tests for quick_sort
pogodaevala Mar 17, 2025
fcd91b4
Merge branch 'DafeCpp:main' into main
pogodaevala Apr 14, 2025
168a03b
tasks 2, 3, 5, 7 done
pogodaevala Apr 19, 2025
8e042f8
clang
pogodaevala Apr 26, 2025
0b3f5e6
camel
pogodaevala Apr 26, 2025
3e39813
Merge branch 'DafeCpp:main' into main
pogodaevala Apr 26, 2025
d8dcaa5
Merge branch 'DafeCpp:main' into main
pogodaevala Apr 26, 2025
2044a75
clang
pogodaevala Apr 26, 2025
77c447f
Merge branch 'DafeCpp:main' into main
pogodaevala Apr 26, 2025
ff90882
task_06 and changes in task_05 and utils
pogodaevala May 3, 2025
d2bae7d
clean
pogodaevala May 3, 2025
f8bea2b
some changes for clang-tidy
pogodaevala May 3, 2025
dbdf4f5
Merge branch 'DafeCpp:main' into main
pogodaevala May 3, 2025
0fd87f9
changes
pogodaevala May 3, 2025
c2a3bdb
changes
pogodaevala May 3, 2025
0290228
changes
pogodaevala May 3, 2025
2157390
task_01
pogodaevala May 4, 2025
290f8d5
task_08 hash_table
pogodaevala May 5, 2025
4a19ead
for clang-tidy
pogodaevala May 5, 2025
e746323
task_04
pogodaevala May 5, 2025
646fe0f
task_09
pogodaevala May 7, 2025
2cdb451
Camel
pogodaevala May 10, 2025
ed441a4
destructor stack
pogodaevala May 10, 2025
234d344
small changes
pogodaevala May 10, 2025
a1d8b0e
small changes
pogodaevala May 10, 2025
dd61cea
tests for iterator and other changes
pogodaevala May 27, 2025
37ea51c
better fish
pogodaevala May 27, 2025
73ef56d
inplace Quicksort
pogodaevala May 31, 2025
796b51c
clang_tidy
pogodaevala Jun 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/src/util.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
#include "util.hpp"

std::vector<double> Smaller(double elem, const std::vector<double>& input) {
std::vector<double> smaller{};
for (auto i : input) {
if (i < elem) {
smaller.push_back(i);
}
}
return smaller;
}

std::vector<double> Bigger(double elem, const std::vector<double>& input) {
std::vector<double> bigger{};
for (auto i : input) {
if (i > elem) {
bigger.push_back(i);
}
}
return bigger;
}

std::vector<double> Eq(double elem, const std::vector<double>& input) {
std::vector<double> eq{};
for (auto i : input) {
if (i == elem) {
eq.push_back(i);
}
}
return eq;
}
7 changes: 7 additions & 0 deletions lib/src/util.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <vector>

std::vector<double> Smaller(double elem, const std::vector<double>& input);

std::vector<double> Bigger(double elem, const std::vector<double>& input);

std::vector<double> Eq(double elem, const std::vector<double>& input);
23 changes: 23 additions & 0 deletions task_01/src/task.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "task.hpp"

#include <stdexcept>

std::pair<int, int> SearchNumbers(int search_num,
const std::vector<int>& data) {
if (data.size() <= 1) {
throw std::invalid_argument("vector is too small");
}
size_t bottom{0};
size_t top{data.size() - 1};
while (bottom != top) {
if (data[bottom] + data[top] == search_num) {
std::pair<int, int> ans{data[bottom], data[top]};
return ans;
} else if (data[bottom] + data[top] > search_num) {
--top;
} else {
++bottom;
}
}
throw std::invalid_argument("no suitable pair");
}
4 changes: 4 additions & 0 deletions task_01/src/task.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <utility>
#include <vector>

std::pair<int, int> SearchNumbers(int search_num, const std::vector<int>& data);
49 changes: 46 additions & 3 deletions task_01/src/test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
#include <gtest/gtest.h>

TEST(Test, Simple) {
ASSERT_EQ(1, 1); // Stack []
}
#include "task.hpp"

TEST(Task1, Simple) {
std::vector<int> data{1, 3, 4, 4, 7, 11};
std::pair<int, int> ans{3, 7};
ASSERT_EQ(SearchNumbers(10, data), ans);
}

TEST(Task1, FirstAndLast) {
std::vector<int> data{1, 2, 3, 4, 5, 99};
std::pair<int, int> ans{1, 99};
ASSERT_EQ(SearchNumbers(100, data), ans);
}

TEST(Task1, Negative) {
std::vector<int> data{-5, -3, 0, 1, 2, 8};
std::pair<int, int> ans{-3, 8};
ASSERT_EQ(SearchNumbers(5, data), ans);
}

TEST(Task1, Simple2) {
std::vector<int> data{10, 11, 12, 13, 14, 15};
std::pair<int, int> ans{10, 15};
ASSERT_EQ(SearchNumbers(25, data), ans);
}

TEST(Task1, SmallVector) {
std::vector<int> data{1, 2};
std::pair<int, int> ans{1, 2};
ASSERT_EQ(SearchNumbers(3, data), ans);
}

TEST(Task1, NoPair) {
std::vector<int> data{1, 2, 3, 4, 5};
ASSERT_THROW(SearchNumbers(100, data), std::invalid_argument);
}

TEST(Task1, Empty) {
std::vector<int> data;
ASSERT_THROW(SearchNumbers(10, data), std::invalid_argument);
}

TEST(Task1, SingleElementVector) {
std::vector<int> data{5};
ASSERT_THROW(SearchNumbers(5, data), std::invalid_argument);
}
4 changes: 3 additions & 1 deletion task_02/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <iostream>

int main() { return 0; }
#include "stack.hpp"

int main() {}
21 changes: 0 additions & 21 deletions task_02/src/stack.cpp

This file was deleted.

123 changes: 114 additions & 9 deletions task_02/src/stack.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,128 @@
#pragma once

#include <stack>
#include <vector>
#include <algorithm>
#include <concepts>

struct EmptyStackError : std::exception {
using std::exception::exception;
};

template <typename T>
struct Node {
T value;
Node<T>* prev = nullptr;
};

template <typename T>
class Stack {
public:
void Push(int value);
int Pop();
Stack(){};
~Stack() {
while (head != nullptr) {
Node<T>* old_head = head;
head = head->prev;
delete old_head;
}
}
void Push(T value);
T Pop();

private:
std::stack<int> data_;
Node<T>* head = nullptr;
};

template <typename T>
requires(std::totally_ordered<T>)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'T' does not refer to a value [clang-diagnostic-error]

  requires(std::totally_ordered<T>)
                                ^
Additional context

task_02/src/stack.hpp:33: declared here

template <typename T>
                   ^

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: a type specifier is required for all declarations [clang-diagnostic-error]

  requires(std::totally_ordered<T>)
  ^

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: expected ';' after top level declarator [clang-diagnostic-error]

Suggested change
requires(std::totally_ordered<T>)
requires(std::totally_ordered<T>);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: expected expression [clang-diagnostic-error]

  requires(std::totally_ordered<T>)
                                  ^

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no member named 'totally_ordered' in namespace 'std' [clang-diagnostic-error]

  requires(std::totally_ordered<T>)
                ^

class MinStack {
public:
void Push(int value);
int Pop();
int GetMin();
MinStack(){};
~MinStack() {
while (head != nullptr) {
Node<T>* old_head = head;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'T' [clang-diagnostic-error]

      Node<T>* old_head = head;
           ^

Node<T>* old_head_min = head_min;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'T' [clang-diagnostic-error]

      Node<T>* old_head_min = head_min;
           ^


head = head->prev;
head_min = head_min->prev;

delete old_head;
delete old_head_min;
}
}
void Push(T value);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: unknown type name 'T' [clang-diagnostic-error]

  void Push(T value);
            ^

T Pop();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: unknown type name 'T' [clang-diagnostic-error]

  T Pop();
  ^

T const GetMin();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: unknown type name 'T' [clang-diagnostic-error]

  T const GetMin();
  ^


private:
std::vector<int> data_;
Node<T>* head = nullptr;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'T' [clang-diagnostic-error]

  Node<T>* head = nullptr;
       ^

Node<T>* head_min = nullptr;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'T' [clang-diagnostic-error]

  Node<T>* head_min = nullptr;
       ^

};

template <typename T>
void Stack<T>::Push(T value) {
if (!head) {
head = new Node<T>;
head->value = value;
} else {
Node<T>* new_head = new Node<T>;
new_head->prev = head;
new_head->value = value;
head = new_head;
}
}

template <typename T>
T Stack<T>::Pop() {
if (head == nullptr) {
throw EmptyStackError();
}
Node<T>* del_node = head;
T val = head->value;
head = head->prev;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут утечка памяти, данные в "старой голове" не удаляются и они будут до завершения работы висеть в памяти

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

во втором стеке тоже

delete del_node;
return val;
}

template <typename T>
requires(std::totally_ordered<T>)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'T' does not refer to a value [clang-diagnostic-error]

  requires(std::totally_ordered<T>)
                                ^
Additional context

task_02/src/stack.hpp:84: declared here

template <typename T>
                   ^

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: a type specifier is required for all declarations [clang-diagnostic-error]

  requires(std::totally_ordered<T>)
  ^

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: expected ';' after top level declarator [clang-diagnostic-error]

Suggested change
requires(std::totally_ordered<T>)
requires(std::totally_ordered<T>);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: expected expression [clang-diagnostic-error]

  requires(std::totally_ordered<T>)
                                  ^

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no member named 'totally_ordered' in namespace 'std' [clang-diagnostic-error]

  requires(std::totally_ordered<T>)
                ^

void MinStack<T>::Push(T value) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: expected ';' after top level declarator [clang-diagnostic-error]

Suggested change
void MinStack<T>::Push(T value) {
void MinStack;<T>::Push(T value) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable has incomplete type 'void' [clang-diagnostic-error]

void MinStack<T>::Push(T value) {
     ^

if (!head) {
head = new Node<T>;
head->value = value;
head_min = new Node<T>;
head_min->value = value;
} else {
Node<T>* new_head = new Node<T>;
Node<T>* new_head_min = new Node<T>;
new_head->prev = head;
new_head->value = value;
new_head_min->prev = head_min;
new_head_min->value = std::min(head_min->value, value);
head = new_head;
head_min = new_head_min;
}
}

template <typename T>
requires(std::totally_ordered<T>)
T MinStack<T>::Pop() {
if (!head || !head_min) {
throw EmptyStackError();
}
Node<T>* del_node = head;
Node<T>* del_node_min = head_min;
T val = head->value;
head = head->prev;
head_min = head_min->prev;
delete del_node;
delete del_node_min;
return val;
}

template <typename T>
requires(std::totally_ordered<T>)
T const MinStack<T>::GetMin() {
if (!head_min) {
throw EmptyStackError();
}
return head_min->value;
}
Loading