DSA - Data Structures and Algorithms
Loading...
Searching...
No Matches
list.h File Reference

This file contains implementation of List class. More...

#include <cstddef>
#include <cstdint>
#include <initializer_list>
#include <iostream>
#include <iterator>
#include <limits>
#include <memory>
#include <ranges>

Go to the source code of this file.

Classes

class  dsa::List< T >
 Implements List using Node with pointer to adjacent elements as internal base. More...
class  dsa::List< T >::NodeBase
 Struct implements base pointer used by List. More...
class  dsa::List< T >::Node
 Implements Node template class with pointer to adjacent elements. More...
class  dsa::List< T >::ListIterator< IF_CONST >
 Implements ListIterator. More...

Functions

template<typename T>
auto dsa::operator+ (const List< T > &list1, const List< T > &list2) -> List< T >
 Construct new object based on two List objects.
template<typename T>
auto dsa::operator<< (std::ostream &out, const List< T > &list) -> std::ostream &
 Overloads operator to print all elements of List.
template<typename T>
auto dsa::operator== (const List< T > &list1, const List< T > &list2) -> bool
 The relational operator compares two List objects.
template<typename T>
auto dsa::operator!= (const List< T > &list1, const List< T > &list2) -> bool
 The relational operator compares two List objects.
template<typename T>
auto dsa::operator< (const List< T > &list1, const List< T > &list2) -> bool
 The relational operator compares two List objects.
template<typename T>
auto dsa::operator> (const List< T > &list1, const List< T > &list2) -> bool
 The relational operator compares two List objects.
template<typename T>
auto dsa::operator<= (const List< T > &list1, const List< T > &list2) -> bool
 The relational operator compares two List objects.
template<typename T>
auto dsa::operator>= (const List< T > &list1, const List< T > &list2) -> bool
 The relational operator compares two List objects.

Detailed Description

This file contains implementation of List class.

Author
Michal Zygmunt

Definition in file list.h.

Function Documentation

◆ operator!=()

template<typename T>
auto dsa::operator!= ( const List< T > & list1,
const List< T > & list2 ) -> bool

The relational operator compares two List objects.

Template Parameters
Ttype of data stored in List
Parameters
[in]list1input container
[in]list2input container
Return values
trueif containers are not equal
falseif containers are equal

Definition at line 1928 of file list.h.

1929 {
1930 return !(operator==(list1, list2));
1931 }
constexpr auto operator==(const Array< T, N > &lhs, const Array< T, N > &rhs) noexcept(noexcept(*lhs.begin()== *rhs.begin())) -> bool
The relational operator compares two Array objects.
Definition array.h:591

◆ operator+()

template<typename T>
auto dsa::operator+ ( const List< T > & list1,
const List< T > & list2 ) -> List< T >

Construct new object based on two List objects.

Template Parameters
Ttype of data stored in List Node
Parameters
[in]list1input List
[in]list2input List
Returns
List<T> List<T> with content of two input lists

Definition at line 1846 of file list.h.

1847 {
1848 List<T> temp(list1);
1849
1850 for (auto iter = list2.cbegin(); iter != list2.cend(); ++iter)
1851 {
1852 T value = *iter;
1853 temp.push_back(value);
1854 }
1855
1856 return temp;
1857 }
Implements List using Node with pointer to adjacent elements as internal base.
Definition list.h:57
auto cend() const -> const_iterator
Function returns pointer to List last Node.
Definition list.h:1225
auto cbegin() const -> const_iterator
Function returns const pointer to List first Node.
Definition list.h:1207

◆ operator<()

template<typename T>
auto dsa::operator< ( const List< T > & list1,
const List< T > & list2 ) -> bool

The relational operator compares two List objects.

Template Parameters
Ttype of data stored in List
Parameters
[in]list1input container
[in]list2input container
Return values
trueif the content of list1 are lexicographically less than the content of list2
falseotherwise

Definition at line 1944 of file list.h.

1945 {
1946 auto list1_iter = list1.cbegin();
1947 auto list2_iter = list2.cbegin();
1948
1949 while (list1_iter != list1.cend() && list2_iter != list2.cend())
1950 {
1951 if (*list1_iter > *list2_iter)
1952 {
1953 return false;
1954 }
1955 if (*list1_iter < *list2_iter)
1956 {
1957 return true;
1958 }
1959
1960 list1_iter++;
1961 list2_iter++;
1962 }
1963
1964 // first n elements are equal
1965 // check sizes
1966 return list1.size() < list2.size();
1967 }
auto size() const -> size_t
Function returns List size.
Definition list.h:1237

◆ operator<<()

template<typename T>
auto dsa::operator<< ( std::ostream & out,
const List< T > & list ) -> std::ostream&

Overloads operator to print all elements of List.

Template Parameters
Ttype of initializer list elements
Parameters
[in,out]outreference to output stream
[in]listList to print
Returns
std::ostream&

Definition at line 1868 of file list.h.

1869 {
1870 if (list.empty())
1871 {
1872 return out;
1873 }
1874
1875 for (auto iter = list.cbegin(); iter != list.cend(); ++iter)
1876 {
1877 T value = *iter;
1878 out << value << ' ';
1879 }
1880
1881 return out;
1882 }
auto empty() const -> bool
Function checks if container has no elements.
Definition list.h:1231

◆ operator<=()

template<typename T>
auto dsa::operator<= ( const List< T > & list1,
const List< T > & list2 ) -> bool

The relational operator compares two List objects.

Template Parameters
Ttype of data stored in List
Parameters
[in]list1input container
[in]list2input container
Return values
trueif the content of list1 are lexicographically less or equal than the content of list2
falseotherwise

Definition at line 1996 of file list.h.

1997 {
1998 return !(operator>(list1, list2));
1999 }
auto operator>(const List< T > &list1, const List< T > &list2) -> bool
The relational operator compares two List objects.
Definition list.h:1980

◆ operator==()

template<typename T>
auto dsa::operator== ( const List< T > & list1,
const List< T > & list2 ) -> bool

The relational operator compares two List objects.

Template Parameters
Ttype of data stored in List
Parameters
[in]list1input container
[in]list2input container
Return values
trueif containers are equal
falseif containers are not equal

Definition at line 1894 of file list.h.

1895 {
1896 if (list1.size() != list2.size())
1897 {
1898 return false;
1899 }
1900
1901 auto list1_iter = list1.cbegin();
1902 auto list2_iter = list2.cbegin();
1903
1904 while (list1_iter != list1.cend())
1905 {
1906 if (*list1_iter != *list2_iter)
1907 {
1908 return false;
1909 }
1910
1911 list1_iter++;
1912 list2_iter++;
1913 }
1914
1915 return true;
1916 }

◆ operator>()

template<typename T>
auto dsa::operator> ( const List< T > & list1,
const List< T > & list2 ) -> bool

The relational operator compares two List objects.

Template Parameters
Ttype of data stored in List
Parameters
[in]list1input container
[in]list2input container
Return values
trueif the content of list1 are lexicographically greater than the content of list2
falseotherwise

Definition at line 1980 of file list.h.

1981 {
1982 return operator<(list2, list1);
1983 }
auto operator<(const List< T > &list1, const List< T > &list2) -> bool
The relational operator compares two List objects.
Definition list.h:1944

◆ operator>=()

template<typename T>
auto dsa::operator>= ( const List< T > & list1,
const List< T > & list2 ) -> bool

The relational operator compares two List objects.

Template Parameters
Ttype of data stored in List
Parameters
[in]list1input container
[in]list2input container
Return values
trueif the content of list1 are lexicographically greater or equal than the content of list2
falseotherwise

Definition at line 2012 of file list.h.

2013 {
2014 return !(operator<(list1, list2));
2015 }