Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using an appropriate definition of ListNode, design a simple linked list class w

ID: 3641805 • Letter: U

Question

Using an appropriate definition of ListNode, design a simple linked list class with only two member functions and a default constructor:
void add(double x);
boolean isMember(double x);
LinkedList( );
The add function adds a new node containing x to the front (head) of the list, while the isMember function tests to see if the list contains a node with the value x. Test your linked list class by adding various numbers to the list and then testing for membership.
Then add a print member function. Test the class by starting with an empty list, adding some elements, and then printing the resulting list out.
Then modify your program to include a member function
int search(double x)
that returns the position of a number x on the list. The first node in the list is at position 0, the second node is at position 1, and so on. If x is not found on the list, the search should return -1. Test the new member function using an appropriate driver program.

Explanation / Answer

#include
#include
using namespace std;

struct nodeType
{
int badge;
string name;
nodeType *link;
};

class LinkedList
{
public:

void add(double x)
{
nodeType *c;
c=new nodeType;
c->badge=x;
c->link=0;
if(head==0)
head=c;
else
{
nodeType *p;
p=head;
while(p->link!=0)
p=p->link;
p->link=c;
}
}



bool isMember(double x)
{
nodeType *c;
c=head;
while(c!=0)
{
if(x==c->badge)
return true;
c=c->link;
}
return false;
}

void print()
{
nodeType *current=head;
if(head!=0)
cout<<"Badge number(s) are "<
while(current != NULL)
{

cout<badge<
current = current -> link;
}
}

LinkedList()
{
head=new nodeType;
head=0;
}
protected:
nodeType *head;
};

int main()
{
cout<<"Please enter badge number"<
LinkedList obj;
double badge;
for(int i=0;i<5;i++)
{
cin>>badge;
obj.add(badge);
}
obj.print();

int num;
cout<<"Please enter a badge# to search for"<
cin>>num;
if(obj.isMember(num))
cout<<"badge number "<<<" exist"<
else
cout<<"badge number "<<<" does not exist"<
}

This should get you started.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote