I believe what I have written at the moment is a singly linked list, and I can't figure out how to delete whatever node the user specifies, I've toyed around with it but I'm stumped.
Here's my specification file:
#include<string>
using namespace std;
class Node
{
Node *prev;
Node *next;
string data;
public:
//Function Declarations
void print(Node *&);
void insertLast(Node *&);
void delAny(Node *&);
};
And here's the implementation file:
#include <iostream>
#include "linkedlist.h"
#include <string>
using namespace std;
void Node::print(Node *&temp)
{
if(temp==NULL) {
cout << "List is Empty " << endl;
}
else {
Node *tmp=temp;
while(tmp!=NULL)
{
cout<<tmp->data<<endl;
tmp=tmp->next;
}
}
}
void Node::insertLast(Node *&temp)
{
Node *newNode;
newNode=new Node;
if (temp==NULL)
{
cout<<"\nEnter Data :";
cin>>newNode->data;
newNode->next=temp;
temp=newNode;
}
else
{
Node *curr;
curr=temp;
while(curr->next!=NULL)
{
curr=curr->next;
}
cout<<"\nEnter Data :";
cin>>newNode->data;
newNode->next=NULL;
curr->next=newNode;
}
}
void Node::delAny(Node *&temp) {
Node *newNode;
newNode=new Node;
if(temp==NULL) {
cout << "List is Empty " << endl;
}
else
{
cout<<"\nEnter Data :";
cin>>newNode->data;
newNode->next=temp;
temp=newNode;
}
I'm not sure what to do with the function to get it to delete whatever the user enters from the list.