Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Get rid of the c + + stuff in his code so it is just in C ( the code is down below ) .
Get rid of the c stuff in his code so it is just in C the code is down below Use the linked list code put it into your IDE and then do a very simple demo of you using it to build a linked list like he did Make sure to show your source code and output for that and some comments to explain what your code is doing
#include
#include
#include "List.h
using namespace std;
List::List
head NULL;
curr NULL;
temp NULL;
void List::AddNodeint addData
nodePtr n new node;
nnext NULL;
ndata addData;
ifhead NULL
curr head;
whilecurrnext NULL
curr currnext;
curr next n;
else
head n;
void List::DeleteNodeint delData
nodePtr delPtr NULL;
temp head;
curr head;
whilecurr NULL && currdata delData
temp curr;
curr currnext;
ifcurr NULL
cout delData "was not in the list
;
delete delPtr;
else
delPtr curr;
curr currnext;
tempnext curr;
ifdelPtr head
head headnext;
temp NULL;
delete delPtr;
cout "The value" delData "was deleted
;
void List::PrintList
curr head;
whilecurr NULL
cout curr data endl;
curr currnext;
#include
#include "List.h
using namespace std;
int mainint argc, char argv
List Rachael;
Rachael.AddNode;
Rachael.AddNode;
Rachael.AddNode;
Rachael.PrintList;
Rachael.DeleteNode;
Rachael.PrintList;
return ;
#ifndef LISTH
#define LISTH
class List
private:
typedef struct node
int data;
node next;
nodePtr;
nodePtr head;
nodePtr curr;
nodePtr temp;
public: This is where the functions go
List;
void AddNodeint addData;
void DeleteNodeint delData;
void PrintList;
;
#endif
Linked list demo
#include
#include
#include
typedef struct node
char data;
struct node next;
nodePtr;
void printlistnodePtr l
nodePtr curr l;
printfTHE LIST IS:
;
while curr NULL
printfs
currdata;
curr currnext;
printf
;
nodePtr addnodenodePtr head, char data
create a new node
nodePtr n mallocsizeofstruct node;
ndata data;
nnext NULL;
first guy in the list
if head NULL
head n;
return head;
hope along to the last guy
nodePtr curr head;
while currnext NULL
curr currnext;
glue him on
currnext n;
return head;
int main
nodePtr head NULL;
lets add a few things to the list
head addnodehead "Once upon";
printlisthead;
head addnodehead "a time";
printlisthead;
head addnodeheadin Hollywood";
printlisthead;
lets construct a string out of some stuff and add it to the list
double x ;
char s;
char xstr;
strcpysMy lucky number ;
sprintfxstrlf x;
strcats xstr;
head addnodehead s;
printlisthead;
return ;
Another example of Linked List Demo
#define CRTSECURENOWARNINGS
#include
#include
typedef struct node
char val;
struct node next;
nodeptr;
void addnodeptr head, char val
nodeptr current head;
while currentnext NULL
current currentnext;
now we can add a new variable
currentnext nodeptr mallocsizeofnodeptr;
currentnextval val;
currentnextnext NULL;
void printlistnodeptr head
nodeptr current head;
while current NULL
printfc
currentval;
current currentnext;
int main
nodeptr head NULL;
head nodeptr mallocsizeofnodeptr;
if head NULL
return ;
headval A;
headnext NULL;
addheadB;
addheadC;
addheadD;
printlisthead;
return ;
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