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

Write a c++ program that compiles on a linux machine and doesn\'t have conio.h i

ID: 3845156 • Letter: W

Question

Write a c++ program that compiles on a linux machine and doesn't have conio.h in it.

it will be very helpful if you can seperate the header files and the .cpp files as well as the main file. thank you so much

Problem Description Let's design a class "linked list" that can store a list of integers. For example: 22 (head) 10 13 Linked List Each node contains a numeric value and a pointer to the next node. The class should at least have the following member functions: 1. Insert an element 2. Delete an element (delete by value) 3. Search an element (search by value) 4. Print the list Now, design another class "sort my list" that has a linked list member variable. Now add a function local sort0, to sort the list in increasing order. You can choose to implement either one of the following three algorithms discussed in class: Selection Sort Insertion Sort Merge Sort Remember: you cannot copy the linked list into an array/vector while you sort it. Create a file "program 02.cpp" that contains the main function. In your main, create an object of "sort my list" class. Define a menu to insert items in your list, delete items from the list, and print the list. Please carefully note that, when you print the list, we expect to see a sorted list of integers. Rubric linked list class 30 points sort my list class: 30 points main function with proper menu options: 20 points

Explanation / Answer

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

class linked_list{
   public:
struct node{
   int num;
   struct node* next;
};

struct node* head = NULL;
struct node* temp1 = NULL;
struct node* temp2 = NULL;
struct node* min = NULL;
void insert(int n){
   struct node* temp = (struct node*)(malloc(sizeof(struct node*)));
   temp->num = n;
   temp->next = head;
   head = temp;
}
void deleteNode(int n){
   struct node* temp = head;
   if(head->num == n){
       head = head->next;
   }
  
   else{
       while(temp->next->num != n){
           temp = temp->next;
       }
       temp->next = temp->next->next;
   }
}
void search(int n){
   struct node* temp = head;
   while(temp != NULL){
       if(temp->num == n){
           cout<<"Number Found"<<endl;
           break;
       }
       temp = temp->next;
   }
}
void printList(){
   struct node* temp = head;
   while(temp!=NULL){
       cout<<temp->num<<" ";
       temp = temp->next;
   }
   cout<<endl;
}


};


class sort_my_list{
   public:
   linked_list l1;
   sort_my_list(linked_list l3){
       l1 = l3;
   }
   void local_sort(linked_list l1){
   int buffer;
   l1.temp1 = l1.head;
   l1.temp2 = l1.head;
   while(l1.temp1 != NULL){
       l1.min = l1.temp1;
       l1.temp2 = l1.temp1;
       while(l1.temp2 != NULL){
           if(l1.min->num > l1.temp2->num){
               l1.min = l1.temp2;
           }
          
           l1.temp2 = l1.temp2->next;
       }
       buffer = l1.temp1->num;
       l1.temp1->num = l1.min->num;
       l1.min->num = buffer;
       l1.temp1 = l1.temp1->next;
   }
}
};


int main(){
   linked_list l1;
   sort_my_list s1(l1);
   int num = 1;
   int number;
   while(num){
       cout<<"Enter the Operations you wish to perform"<<endl;
       cout<<"Press 0 for Exit"<<endl;
       cout<<"Press 1 for Insert"<<endl;
       cout<<"Press 2 for Delete"<<endl;
       cout<<"Press 3 for Search"<<endl;
       cout<<"Press 4 for Print"<<endl;
       cout<<"Press 5 for SortLocal"<<endl;
       cin>>num;
       if(num == 1){
           cout<<"Enter a number"<<endl;
           cin>>number;
           l1.insert(number);
       }
       else if(num == 2){
           cout<<"Enter a number"<<endl;
           cin>>number;
           l1.deleteNode(number);
       }
       else if(num == 3){
           cout<<"Enter a number"<<endl;
           cin>>number;
           l1.search(number);
       }
       else if(num == 4){
           l1.printList();
       }
       else if(num == 5){
           s1.local_sort(l1);
       }
      
   }
   /*l1.insert(13);
   l1.insert(7);
   l1.insert(10);
   l1.insert(22);
   l1.printList();
   l1.search(13);
  
   sort_my_list s1(l1);
   s1.local_sort();
   l1.printList();*/
   return 0;
}

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