modified: assignment2/as2/as2.pro

modified:   assignment2/as2/main.cpp
This commit is contained in:
mooophy
2014-12-04 17:39:10 +13:00
parent 1d1c7b532b
commit 1735ce708b
2 changed files with 67 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
CONFIG += c++11
SOURCES += main.cpp

View File

@@ -1,10 +1,74 @@
#include <iostream>
#include <stdexcept>
namespace ads {
template<typename Data> struct Node
{
Data value;
Node* next;
};
template<typename Node>
class List
{
public:
using DataType = decltype(Node::Data);
List() = default;
void push_front(DataType const& new_data)
{
do_push_front(new_data);
}
DataType const& front()const
{
return head_->value;
}
void pop()
{
do_pop();
}
bool empty()const
{
return !head_ and !tail_;
}
private:
Node* head_{nullptr};
Node* tail_{nullptr};
std::size_t size_{0};
void do_push_front(DataType const& new_data)
{
if(empty())
head_ = tail_ = new Node{new_data, nullptr};
else
head_ = new Node{new_data, head_};
++size_;
}
void do_pop()
{
if(empty())
throw std::runtime_error{"underflow!"};
head_ =head_->next;
--size_;
}
};
}//namespace
using namespace std;
int main()
{
cout << "Hello World!" << endl;
ads::List<ads::Node<int>> l;
return 0;
}