Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "item.h"
- #include <functional>
- #include <iostream>
- #include <memory>
- #include <utility>
- template <typename T, typename U>
- void insert_item(std::unique_ptr<Item<T>>* start, U&& val, std::function<bool(const T&, const Item<T>&)> insert_before) {
- while (*start && !insert_before(val, **start)) {
- start = &(*start)->next;
- }
- *start = std::make_unique<Item<T>>(std::forward<U>(val), std::move(*start));
- }
- template <typename T>
- void remove_item(std::unique_ptr<Item<T>>* start, const T& val, std::function<bool(const Item<T>&, const T&)> value_equal) {
- while (*start && !value_equal(**start, val)) {
- start = &(*start)->next;
- }
- if (*start) {
- *start = std::move((*start)->next);
- }
- else {
- std::cout << "Item " << val << " does not exist!\n";
- }
- }
- template <typename T>
- void remove_all(std::unique_ptr<Item<T>>& start) {
- start.reset();
- }
- template <typename T>
- void print_list(Item<T>* start) {
- while (start != nullptr) {
- start = start->print_get_next();
- }
- }
- template <typename T>
- void print_iterator(Item<T>* start) {
- if (start != nullptr) {
- for (auto item : *start) {
- item->print_get_next();
- }
- }
- }
- template <typename T>
- void print_array(Item<T>* start) {
- auto item = start;
- for (int i = 0; item != nullptr; ++i) {
- item = (*start)[i].print_get_next();
- }
- }
- template <typename T>
- void print_recursive(Item<T>* start) {
- if (start != nullptr) {
- print_recursive(start->print_get_next());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement