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

NEED HELP Filling the methods? #include <iostream> using namespace::std; struct

ID: 668794 • Letter: N

Question

NEED HELP Filling the methods?

#include <iostream>

using namespace::std;

struct node

{

int data;

   node * p;

};

int length(const char *p)

{

int ans = 0;

for (int i = 0; p[i]; i++){

       ans++;

   }

return ans;

}

int lengthR(const char *p)

{

if (*p == '') return 0;

return 1 + lengthR(p + 1);

}

int lengthR(const node * st)

{

if (st == NULL) return 0;

return 1 + lengthR(st->p);

}

int length(const node * st)

{

const node * walker = st;

if (st == NULL) return 0;

return walker + (length(st->);

}

int sum(const int *, int howMany)

{

}

int sumR(const int *, int howMany)

{

}

int sum(const node *p)

{

}

int sumR(const node *p)

{

}

int max(const char *ptr)

{

}

int maxR(const node *ptr)

{

}

void makeLinkedList(node * & start)

{

}

void printLinkedList(ostream &, const node *)

{

}

void deleteLinkedList(node *)

{

}

int length( const char *);

int lengthR(const char *);

int length( const node *);

int lengthR(const node *);

int sum(const int *, int howMany);

int sumR(const int *, int howMany);

int sum(const node *);

int sumR(const node *);

int sum(const char *); // sum ASCII values

int sumR(const char *); // sum ASCII value

int max(const char *);

int maxR(const char *);

int max(const int * , int howMany);

int maxR(const int *, int howMany);

int max(const node *);

int maxR(const node *);

void makeLinkedList(node * & start);

void printLinkedList(ostream &, const node *);

void deleteLinkedList(node *);

void main()

{

   cout << length("abcdefgh") << endl;

   cout<< lengthR("abcd");

   node * st;

   makeLinkedList(st);

   cout << st->p->p->data << endl;

   cout << lengthR(st) << endl;

   printLinkedList(cout,st);

   deleteLinkedList(st);

}

void makeLinkedList(node * & start)

{

// make the linked list 7 -> 12 -> 6 -> 15 -> 3

   start = new node;

   start->data = 7;

   start->p = new node;

   start->p->data = 12;

   start->p->p = new node;

   start->p->p->data= 6;

   start->p->p->p = new node;

   start->p->p->p->data= 15;

   start->p->p->p->p= new node;

   start->p->p->p->p->data= 3;

start->p->p->p->p->p= NULL;

}

void printLinkedList(ostream & out, const node * s)

{

const node * walker = s;

while ( walker != NULL)

   {

out << walker->data << " ";

       walker = walker->p;

   }

   out << endl;

}

void deleteLinkedList(node *s)

{

if ( s == NULL ) return; // 0 nodes

if ( s->p == NULL ) // 1 node

   {

       delete s;

       return;

   }

   node * prev = s;

   node * current = prev->p;

while ( current != NULL )

   {

   cout << "deleting " << prev-> data << endl;

   delete prev;

   prev = current;

   current = current->p;

   }

   cout << "deleting " << prev-> data << endl;

delete prev;

   cout << "decestructor leaving " << endl;

}

Explanation / Answer

#include<conio.h>
#include<stdio.h>
struct node
{
int i;
struct node *next;
};
void main()
{
struct node *first;
struct node *last;
struct node *temp;
int ch,user,add,cnt=0,t=0;
struct node *p;
clrscr();
printf(" 1.CREATION");
printf(" 2.INSERT AT STARTING");
printf(" 3.INSERT AT MIDDLE(USER'S CHOICE)");
printf(" 4.INSERT AT END");
printf(" 5.DELETE 1ST NODE");
printf(" 6.DELETE LAST NODE");
printf(" 7.DELETE MIDDLE NODE(USER'S CHOICE)");
printf(" 8.DISPLAY");
printf(" 10.EXIT");
scanf("%d",&user);
while(user!=10)
{
if(user==1)
{
printf(" ENTER DATA ::: ");
first=(struct node*)malloc(sizeof(struct node));
scanf("%d",&ch);
first->i=ch;
first->next=0;
p=first;
cnt=1;
}
if(user==2)
{
p=(struct node*)malloc(sizeof(struct node));
printf(" ENTER DATA FOR 1ST NODE");
scanf("%d",&p->i);
p->next=first;
first=p;
cnt++;
}
if(user==4)
{
p=(struct node*)malloc(sizeof(struct node));
printf(" ENTER DATA FOR LAST NODE");
scanf("%d",&p->i);
temp=first;
while(temp->next!=0)
{
temp=temp->next;
}
temp->next=p;
p->next=0;
cnt++;
}
if(user==3)
{
printf(" ENTER ANY ADDRESS BETWEEN 1 and %d",cnt);
scanf("%d",&add);
t=1;
p=first;
while(t!=add)
{
p=p->next;
t++;
}
temp=(struct node*)malloc(sizeof(struct node));
printf(" ENTER DATA FOR NODE");
scanf("%d",&temp->i);
temp->next=p->next;
p->next=temp;
cnt++;
}
if(user==5)
{
p=first;
first=p->next;
free(p);
}
if(user==6)
{
p=first;
while(p->next->next!=0)
{
p=p->next;
}
p->next=0;
free(p->next->next);
}
if(user==8)
{
p=first;
while(p!=0)
{
printf(" %d",p->i);
p=p->next;
}
}
if(user==7)
{
printf(" ENTER ANY ADDRESS BETWEEN 1 and %d",cnt);
scanf("%d",&add);
t=1;
p=first;
while(t<add-1)
{
p=p->next;
t++;
}
temp=p->next;
p->next=temp->next;
free(temp);
cnt--;
}
printf(" 1.CREATION");
printf(" 2.INSERT AT STARTING");
printf(" 3.INSERT AT MIDDLE(USER'S CHOICE)");
printf(" 4.INSERT AT END");
printf(" 5.DELETE 1ST NODE");
printf(" 6.DELETE LAST NODE");
printf(" 7.DELETE MIDDLE NODE(USER'S CHOICE)");
printf(" 8.DISPLAY");
printf(" 10.EXIT");
scanf("%d",&user);
}
getch();
}