Question
Please help me fix my compile errors , C++ linkedlist program is written but i cant fix this last error LinkedList.h File #ifndef LINKEDLIST_H #define
Please help me fix my compile errors , C++ linkedlist program is written but i cant fix this last error
LinkedList.h File
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include
#include
using namespace std;
struct node
{
int data;
struct node *next;
}*head;
class LinkedList
{
public:
LinkedList();
struct node *create(string name);
void insert(string name);
void remove(string name);
void print(string name);
void printAll();
};
#endif
LinkedList.cpp
#include "LinkedList.h"
#include
#include
using namespace std;
class LinkedList
{
LinkedList()
{
head = NULL;
}
struct node *create(string name)
{
struct node *t;
t = new(struct node);
if (t == NULL)
{
cout<<"Memory not allocated "< return 0; } else { t->data = name; t->next = NULL; return t; } } void insert(string name) { struct node *t, *p; t = create(name); if (head == NULL) { head = t; head->next = NULL; } else { p = head; head = temp; head->next = p; } } void remove(string name) { struct node *pre = NULL, *del = NULL; if (_head->data == name) { del = head; head = del->next; delete del; return; } pre = head; del = head->next; while (del != NULL) { if (del->data == name) { pre->next = del->next; delete del; break; } pre = del; del = del->next; } } void print(string name) { bool f = false; if (head == NULL) { cout<<"There are no entries in the list to display"< return; } cout << "Displaying the single entry in the list: "endl; cout<< name < struct node *t; t = head; while (t != NULL) { if (t->data == name) { f = true; cout<< name << "is in the List "< } t = t->next; } if (!f) cout< } void printAll() { int count =0; struct node *t; if (head == NULL) { cout<<"There are no entries in the list to display"< return; } t = head; while (temp != NULL) { count++; t = t->next; } cout<<"Displaying all" < while (temp != NULL) { cout< t = t->next; } cout<<"There are no entries in the list to display"< } }; LinkedList-main.cpp#include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started