I need help with this assignment for school, and I am stuck on what the problem is...Any help or guidance is appreciated!
My instructions for school:
(Circular linked lists) This chapter defined and identified various operations on a circular linked list.
Write the definitions of the class circularLinkedList and its member functions. (You may assume that the elements of the circular linked list are in ascending order.)
//In my main.cpp file
//This program tests various operation of a linked list
//45 67 23 89 -999
#include <iostream>
#include "circularLinkedList.h"
usingnamespace std;
int testCopyConstructor(H_circularLinkedList uint);
int main()
{
int input=0;
int A;
LinkedList One;
while (1)
{
if (input==0)
{
cout<<"1. Add\n2. Delete\n3. Display\n";
cout<<"Enter your choice\n";
cin>>input;
}
elseif (input==1)
{
cout<<"Enter the data\n";
cin>>A;
One.add(A);
cout<<"Press 0 to go back to main menu\n";
cin>>input;
}
elseif (input==2)
{
if (One.empty())
cout<<"The list is empty\n";
else
{
cout<<"Enter the data to be deleted\n";
cin>>A;
One.Delete(A);
}
cout<<"Press 0 to go back to main menu\n";
cin>>input;
}
elseif (input==3)
{
if (One.empty())
cout<<"The list is empty\n";
else
One.isplay();
cout<<"Press 0 to go back to main menu\n";
cin>>input;
}
}
}
//In my circularLinkedList.cpp file
#ifndef H_circularLinkedList
#define H_circularLinkedList
#include <iostream>
#include <cassert>
usingnamespace std;
struct node
{
int data;
node * next;
};
class LinkedList
{
public:
LinkedList();
void add(int A);
bool empty(); // return true if the list is empty, otherwise return false void InsertInOrder(ElementType x);//insert a value x in numerical order in the list
void Delete(int x); //if value x is in the list, remove x
void Display();// Display the data values in the list
void isplay();
private:
node * first;//pointer to the first node in the list
};
LinkedList::LinkedList()
{
first=NULL;
}
void LinkedList::add(int A)
{
if (first==NULL)
{
first=new node;
first->data=A;
first->next=first;
}
elseif (first->next==first)
{
node *curr=first->next;
curr=new node;
curr->data=A;
curr->next=first;
first->next=curr;
}
else
{
node *curr=first->next;
node *prev=NULL;
while (curr!=first)
{
prev=curr;
curr=curr->next;
}
curr=new node;
curr->data=A;
curr->next=first;
prev->next=curr;
}
}
bool LinkedList::empty()
{
if (first==NULL)
returntrue;
elsereturnfalse;
}
void LinkedList::Delete(int A)
{
node *curr=first->next;
node *prev=NULL;
bool flag=true;
if (first->data==A)
{
first=first->next;
delete first;
flag=false;
}
else
{
while (flag && curr!=first)
{
if (curr->data==A)
{
prev->next=curr->next;
delete curr;
flag=false;
}
prev=curr;
curr=curr->next;
}
if (flag==true)
cout<<"Data not foundn";
}
}
void LinkedList::isplay()
{
cout<<first->data<<endl;
node *curr=first->next;
while (curr!=first)
{
cout<<curr->data<<endl;
curr=curr->next;
}
}
#endif
Then your compiler will be giving you helpful compiler messages, stating what line is failing to compile, and what the specific problem is on that line. Use that information to help fix the problem.
If there are specific errors you don't understand, or can't fix, then you can always ask us specific questions about those errors, provided you give us the information you have about them.
my program won't run
That one's easy. It won't run, because it doesn't exist. If the code doesn't compile, then you simply don't have an application to run. You're welcome.