Answer to Question #241735 in C++ for Zohaib

Question #241735

Your task


1) void PrinList(),

2)int search_Element(int X),3)

void Insert_Element(int X),

4)void

Insert_Element_at(int X, int pos),

5) bool Delete_Element(int X),

6) bool is_Empty(),

7)int Length(),

8) void Print_Reverse_List(),

9) void Empty_List(),

10) void Copy_List(…)


Note:

1)Perform the above tasks for linked list

2)make copy, default and parameterized constructors

3)make a menu in main and call the functions through the manu

4)No global declarations


1
Expert's answer
2021-09-24T13:26:12-0400
#include <iostream>

using namespace std;

class List {
public:
    int item;
    int pos = 0;
    List *nextNode;
};
void Print_Reverse_List(List *node) {
    if (node == NULL)
        return;
    Print_Reverse_List(node->nextNode);
    cout << node->item << " ";
}
void Insert_Element(List **head, char data) {
    List *node = new List();
    node->item = data;
    node->nextNode = (*head);
    (*head) = node;
}
void PrinList(List *node) {
    List *temp = node;
    while (temp != NULL) {
        cout << temp->item << "  ";
        node->pos++;
        temp = temp->nextNode;
    }
    cout << "\n";
}
void search_Element(List *node, int x) {
    List *temp = node;
    while (temp != NULL) {
        int data = temp->item;
        if (data == x) {
            cout << "\nElement found\n";
        }
        temp = temp->nextNode;
    }
    cout << "\n";
}
int Length(List *node) {
    return node->pos;
}
bool is_Empty(List *node) {
    if (node->pos == 0) {
        return true;
    } else {
        return false;
    }
}
void Copy_List(List *node, List *list) {
    List *temp = node;
    while (temp != NULL) {
        int data = temp->item;
        Insert_Element(&list, data);
        temp = temp->nextNode;
    }
    cout << "The copied list is:\n";
    PrinList(list);
}
int main()
{
    List *node = NULL;
    Insert_Element(&node, 4);
    Insert_Element(&node, 3);
    Insert_Element(&node, 2);
    Insert_Element(&node, 1);
    PrinList(node);
    Print_Reverse_List(node);
    cout << "\nThe length is: " << Length(node) << endl;
    search_Element(node, 3);
    if (is_Empty(node) == 0) {
        cout << "\nThe list is not empty\n";
    } else {
        cout << "\nThe list is  empty\n";
    }
    List *list = NULL;
    Copy_List(node, list);
    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