Answer to Question #242049 in C++ for Pain

Question #242049

Considering the following functions have been made

1)void Print_Reverse_List(List* node)

2)void Insert_Element(List** head, int data)

3)void PrinList(List* node)

4)void search_Element(List *node, int x)

5)int Length(List *node)

Your task is to create the following functions for the given code:

1)Insert_Element_at(int x)

2)bool is_Empty()

3)bool Delete_Element(int x)

4)void Empty_List()

5)void Copy_List(...)

make menu for the five functions


class List{

public:

int item;

int pos;

List* nextNode

};


List* linkList=NULL;



int ch=-1;

int number;

int position;

while(ch!=6){

cout<<"1. Insert Element\n";

cout<<"2. Print List\n";

cout<<"3. Search Element\n";

cout<<"4. Display Length of List\n";

cout<<"5. Print Reverse List\n";

cout<<"6. Exit\n";

cout<<"Your choice: ";

cin>>ch;

cout<<"\n";

switch(ch){

case 1:

}


1
Expert's answer
2021-09-26T12:28:00-0400


#include <bits/stdc++.h>
using namespace std;


struct Node {
	int d;
	struct Node* nt;
};


void reverseUtil(Node* cur, Node* prev, Node** hd);




void reverse(Node** hd)
{
	if (!hd)
		return;
	reverseUtil(*hd, NULL, hd);
}


void reverseUtil(Node* cur, Node* prev, Node** hd)
{
	if (!cur->nt) {
		*hd = cur;


		cur->nt = prev;
		return;
	}


	Node* nt = cur->nt;
	cur->nt = prev;


	reverseUtil(nt, cur, hd);
}


Node* newNode(int key)
{
	Node* temp = new Node;
	temp->d = key;
	temp->nt = NULL;
	return temp;
}


void printlist(Node* hd)
{
	while (hd != NULL) {
		cout << hd->d << " ";
		hd = hd->nt;
	}
	cout << endl;
}


int main()
{
	Node* hd1 = newNode(1);
	hd1->nt = newNode(2);
	hd1->nt->nt = newNode(3);
	hd1->nt->nt->nt = newNode(4);
	hd1->nt->nt->nt->nt = newNode(5);
	hd1->nt->nt->nt->nt->nt = newNode(6);
	hd1->nt->nt->nt->nt->nt->nt = newNode(7);
	hd1->nt->nt->nt->nt->nt->nt->nt= newNode(8);
	printlist(hd1);
	reverse(&hd1);
	printlist(hd1);
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS