Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class IntNode {
- private:
- int16_t elem;
- IntNode* last;
- IntNode* next;
- friend class IntLinkedList;
- };
- class IntLinkedList {
- private:
- IntNode* head;
- IntNode* tail;
- public:
- IntLinkedList();
- bool empty() const;
- void addFront(int e);
- void removeFront();
- void print() const;
- };
- IntLinkedList::IntLinkedList() {
- head = new IntNode;
- tail = new IntNode;
- head->next = tail;
- tail->last = head;
- }
- bool IntLinkedList::empty() const {
- if (head->next == tail)
- return true;
- else
- return false;
- }
- void IntLinkedList::addFront(int e) {
- IntNode* u=new IntNode;
- IntNode* v = head ->next;
- u->elem = e;
- u->next = v;
- u->last = v->last;
- //v->last = head->last;
- v->last->next = u;
- v->last = u;
- }
- void IntLinkedList::removeFront() {
- IntNode* v = head->next;
- IntNode* u = v->last;
- IntNode* w = v->next;
- u->next = w;
- w->last = u;
- delete v;
- }
- void IntLinkedList::print() const {
- IntNode* temp = head->next;
- while (temp != tail) {
- cout << temp->elem << '\n';
- temp = temp->next;
- }
- }
- int main(){
- IntLinkedList myList;
- for (int i = 0;
- i < 10;
- ++i) {
- myList.addFront(i);
- }
- for (int i = 0;
- i < 3;
- ++i) {
- myList.removeFront();
- }
- myList.print();
- /*for (const auto& s : myList) {
- cout << s;
- }*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement