Write Linked Implementation List List Node Element Contains Pointers Previous Next Element Q37114849

Write a linked implementation of a list where each list nodeelement contains pointers to both the previous and next element inthe list.  (C++)

// ListNode.h
#ifndef _LISTNODE_H
#define _LISTNODE_H

#include <cstdlib>

typedef int ItemType;

class ListNode {
   friend class LList;

public:
   ListNode(ItemType item, ListNode* link = NULL);

private:
   ItemType item_;
   ListNode *link_;
};

inline ListNode::ListNode(ItemType item, ListNode *link)
{
   item_ = item;
   link_ = link;
}

#endif // _LISTNODE_H

// LList.h
#ifndef _LLIST_H
#define _LLIST_H

#include “ListNode.h”

class LList {

public:
   LList(); // sonstructor
   LList(const LList& source); // copyconstructor
   ~LList(); // destructor

   LList& operator=(const LList& source); //assignment operator
   int size() { return size_; } // size method
   void append(ItemType x); // append operator
   void insert(size_t i, ItemType x); // insertionoperator
  

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.