123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- #ifndef STACKED_LIST_HPP
- #define STACKED_LIST_HPP
- #include <iostream>
- #include <cstdint>
- #include <deque>
- #include <stack>
- #include <cassert>
- using namespace std;
- #define SIZE 1024
- typedef uint16_t NInd;
- typedef int16_t NData;
- class StackedListNode{
- public:
- StackedListNode();
- NInd previous,next;
- NData data;
- };
- class StackedList{
- public:
- private:
-
- void fill(NData* array,size_t s);
-
-
- NInd new_node();
- public:
-
-
- size_t size;
-
-
- StackedListNode nodes[SIZE];
-
- NInd indices[SIZE];
-
- StackedList();
-
- StackedList(NData* array,size_t s);
-
- void clear();
-
-
- void erase(NInd i);
-
- NData first();
-
-
- void full_show() const;
-
- void init(size_t s);
-
-
- void init(NData* array,size_t s);
-
-
- NInd insert_before(NInd i,NData data);
-
-
- NInd insert_after(NInd i,NData data);
-
- bool is_empty() const;
-
- NData last();
- };
- ostream& operator<<(ostream& os,const StackedList&);
- inline
- StackedListNode::StackedListNode(){}
- inline
- StackedList::StackedList(){
- clear();
- nodes[0].data=0;
- nodes[0].previous=0;
- nodes[0].next=0;
- }
- inline
- StackedList::StackedList(NData* array,size_t s){
- clear();
- fill(array,s);
- }
- inline void
- StackedList::clear(){
- size=0;
- for(size_t i=0;i<SIZE;++i) indices[i]=i;
- nodes[0].previous=0;
- nodes[0].next=0;
- }
- inline void
- StackedList::init(NData* array,size_t s){
- clear();
- fill(array,s);
- }
- inline bool
- StackedList::is_empty() const{
- return size==0;
- }
- inline NData
- StackedList::first(){
- return nodes[nodes[0].next].data;
- }
- inline NData
- StackedList::last(){
- return nodes[nodes[0].previous].data;
- }
- inline NInd
- StackedList::new_node(){
- return indices[++size];
- }
- #endif
|