Skip to content

Instantly share code, notes, and snippets.

@tjkhara
Created October 30, 2018 13:15
Show Gist options
  • Select an option

  • Save tjkhara/2091dcc09c6d4b76e33ee5ef068caa57 to your computer and use it in GitHub Desktop.

Select an option

Save tjkhara/2091dcc09c6d4b76e33ee5ef068caa57 to your computer and use it in GitHub Desktop.
/*********************************************************************
** Program name: DoublyLinkedList.h
** Author: Tajeshwar Singh Khara
** Date: 30-10-2018
** Description: Specification file for list class.
*********************************************************************/
#ifndef LAB6_DOUBLYLINKEDLIST_DOUBLYLINKEDLIST_H
#define LAB6_DOUBLYLINKEDLIST_DOUBLYLINKEDLIST_H
#include <iostream>
using std::cout;
using std::endl;
#include <fstream>
using std::ifstream; // For file input
class DoublyLinkedList
{
protected:
// Node class
class Node
{
public:
int value; // value in each node
Node* next; // Pointer to next node
Node* prev; // Pointer to previous node
// Constructor
Node(int valueIn, Node* nextIn = nullptr, Node* prevIn = nullptr)
{
value = valueIn;
next = nextIn;
prev = prevIn;
}
};
Node* head; // List head pointer
// Tail pointer points to the last node in the linked list
Node* tail; // List tail pointer
public:
// Constructor
DoublyLinkedList()
{
// If the list is empty the head and tail should point to null
head = nullptr; // List starts out empty
tail = nullptr; // List starts out empty
}
// Destructor
~DoublyLinkedList();
// Add a new node to the head
void addToHead(int number);
// Add a new node to the tail
void addToTail(int number);
// Delete first node
void deleteFirstNode();
// Delete last node
void deleteLastNode();
// Reverse traverse
void reverseTraverse();
// Traverse
void traverse();
void remove(int number);
// Print list
void displayList() const;
// Print the value of the node the head is pointing to
void printHeadValue();
// Print the value of the node the head is pointing to
void printTailValue();
// Create linked list from a text file
void createLinkedListFromTextFile();
};
#endif //LAB6_DOUBLYLINKEDLIST_DOUBLYLINKEDLIST_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment