
Explanation of Solution
Program code:
//include the required header files
#include<iostream>
#include<cstdio>
#include<cstdlib>
/* Node Declaration*/
using namespace std;
//create a structure
struct node
{
//structure members
int info;
struct node *next;
struct node *prev;
}*start;
/*Class Declaration */
class double_llist
{
//public access modifier
public:
//declare the member functions
void create_list(int value);
void add_begin(int value);
void add_after(int value, int position);
void delete_element(int value);
void search_element(int value);
void display_dlist();
void count();
void reverse();
//define a method
double_llist()
{
//set the value of start
start = NULL;
}
};
/* Main*/
int main()
{
//declare the required variables
int choice, element, position;
double_llist dl;
//iterate a while loop
while (1)
{
//display the choices
cout<<endl<<"----------------------------"<<endl;
cout<<endl<<"Operations on Doubly linked list"<<endl;
cout<<endl<<"----------------------------"<<endl;
cout<<"1.Create Node"<<endl;
cout<<"2.Add at begining"<<endl;
cout<<"3.Add after position"<<endl;
cout<<"4.Delete"<<endl;
cout<<"5.Display"<<endl;
cout<<"6.Count"<<endl;
cout<<"7.Reverse"<<endl;
cout<<"8.Quit"<<endl;
//prompt the user to enter the choice
cout<<"Enter your choice : ";
cin>>choice;
//switch cases
switch ( choice )
{
//case 1
case 1:
//prompt the user to enter the element
cout<<"Enter the element: ";
//scan for the value
cin>>element;
//call the method create_list(element)
dl.create_list(element);
//new line
cout<<endl;
//break fron the case
break;
case 2:
//prompt the user to enter the element
cout<<"Enter the element: ";
//scan for the value
cin>>element;
//call the method add_begin(element)
dl.add_begin(element);
//new line
cout<<endl;
//break fron the case
break;
case 3:
//prompt the user to enter the element
cout<<"Enter the element: ";
//scan for the value
cin>>element;
//prompt the user to enter the position
cout<<"Insert Element after postion: ";
cin>>position;
//call the method add_after(element)
dl.add_after(element, position);
//new line
cout<<endl;
//break fron the case
break;
case 4:
//if the condition is true
if (start == NULL)
{
//print the statement
cout<<"List empty,nothing to delete"<<endl;
//break fron the condition
break;
}
//prompt the user to enter the element
cout<<"Enter the element for deletion: ";
//scan for the value
cin>>element;
//call the method delete_element(element)
dl.delete_element(element);
//new line
cout<<endl;
//break fron the case
break;
case 5:
//call the method display_dlist(element)
dl.display_dlist();
//new line
cout<<endl;
//break fron the case
break;
case 6:
//call the method count(element)
dl.count();
//break fron the case
break;
case 7:
//if the condition is true
if (start == NULL)
{
//print the statement
cout<<"List empty,nothing to reverse"<<endl;
//break fron the condititon
break;
}
//call the method reverse(element)
dl.reverse();
//new line
cout<<endl;
//break fron the case
break;
case 8:
//exit from while loop
exit(1);
default:
//print the statement
cout<<"Wrong choice"<<endl;
}
}
//return zero
return 0;
}
/* Create Double Link List*/
void double_llist::create_list(int value)
{
//create struct vaiable
struct node *s, *temp;
//set the value of temp
temp = new(struct node);
//insert the value
temp->info = value;
//set next as Null
temp->next = NULL;
//if the condition is true
if (start == NULL)
{
//set prev equal to Null
temp->prev = NULL;
//set start equal to temp
start = temp;
}
else
{
//set s equal to start
s = start;
//iterate a while loop
while (s->next != NULL)
//assign the value
s = s->next;
s->next = temp;
temp->prev = s;
}
}
/* Insertion at the beginning */
void double_llist::add_begin(int value)
{
//if the condition is true
if (start == NULL)
{
//print the statement
cout<<"First Create the list."<<endl;
return;
}
//inserting the element
struct node *temp;
temp = new(struct node);
temp->prev = NULL;
temp->info = value;
temp->next = start;
start->prev = temp;
start = temp;
cout<<"Element Inserted"<<endl;
}
/* Insertion of element at a particular position*/
void double_llist::add_after(int value, int pos)
{
//if the condition is true
if (start == NULL)
{
//print the statement
cout<<"First Create the list."<<endl;
//return
return;
}
//create struct variables
struct node *tmp, *q;
//create the required variables
int i;
q = start;
//iterate a for loop
for (i = 0;i < pos - 1;i++)
{
//set the value of q
q = q->next;
//if the value of q equal to null
if (q == NULL)
{
//print the statement
cout<<"There are less than ";
cout<<pos<<" elements...

Want to see the full answer?
Check out a sample textbook solution
Chapter 3 Solutions
Data structures and algorithms in C++
- also provide the number of moves(actions) made at state A and moves(actions) made state B. INCLUDE Java program required(this question is not graded)arrow_forwardYou are given a class that processes purchases for an online store. The class receives calls to: • Retrieve the prices for items from a database • Record the sold items • Update the database • Refresh the webpage a. What architectural pattern is suitable for this scenario? Illustrate your answer by drawing a model for the solution, showing the method calls/events. b. Comment on how applying this pattern will impact the modifiability of the system. c. Draw a sequence diagram for the update operation.arrow_forward2. The memory management has contiguous memory allocation, dynamic partitions, and paging. Compare the internal fragmentation and external fragmentation for these three approaches. [2 marks] 3. Suppose we have Logical address space = 24 = 16 (m = 4), Page size=2² =4 (n = 2), Physical address space = 26 = 64 (r = 6). Answer the following questions: [4 marks] 1) Total # of pages ? 2) Total # of frames ? 3) Number of bits to represent logical address? 4) Number of bits to represent offset ? 5) Number of bits to represent physical address? 6) Number of bits to represent a page number? 7) Number of bits to represent a frame number / 4. What is translation look-aside buffers (TLBS)? Why we need them to implement the page table? [2 marks] 5. Why we need shared pages for multiple processes? Give one example to show the benefits. [2 marks] 6. How to implement the virtual memory by using page out and page in? Explain with an example. [2 marks] 7. We have a reference string of referenced page…arrow_forward
- Good morning, please solve this trying to follow this criteria. (use Keil) Abstract describing the requirements and goals of the assignment. List file with no errors or warnings. Brief description of your implementation design and code. Debugging screen shots for different scenarios with your reference and comments. Conclusion (and please give me the code without errors, make sure it is working)arrow_forwardGood mrng, please solve this trying to follow this criteria. (use Keil) Abstract describing the requirements and goals of the assignment. List file with no errors or warnings. Brief description of your implementation design and code. Debugging screen shots for different scenarios with your reference and comments. Conclusion (and please give me the code without errors, make sure it is working)arrow_forward#include <stdio.h> #include <stdlib.h> #include <unistd.h> int global_var = 42; // int* function(int *a) { int local_var = 10; // *a = *a + local_var; int *local_pointer = (int *)malloc (size of (int) * 64); // Allocated array with 64 integers return local_pinter; } int main() { int local_main[1024*1024*1024*1024*1024] = {0}; // initialize an array and set all items as 0 int *heap_var = (int *)malloc(size of(int) * 16); // Allocated array with 16 integers *heap_var = 100; function(heap_var); printf(“the value is %d\n”, *heap_var); free(heap_var); // release the memory return 0; } 1) draw the memory layout of the created process, which should include text, data, heap and stack [2 marks]. 2) Indicate which section the variables are allocated [2 marks]: global_var local_var, local_pointer local_main heap_var, *heap_var (the data that it points to) 3) Does this code have memory leaking (heap memory is not released)? [2 marks] 4) The…arrow_forward
- 8. List three HDD scheduling algorithms. [2 marks] 9. True or False? The NVM has the same scheduling algorithms with HDD. Explain why? [2 marks] 10. Why the modern mouses use polling to detect movements instead of interrupts? [2 marks] 11. What is thrashing? How does it happen? [2 marks] 12. Given a reference string of page numbers 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 and 4 frames show how the page replacement algorithms work, and how many page faults? [6 marks], 1) FIFO algorithm? [2 marks] 2) Optimal algorithm? [2 marks] 3) LRU algorithm? [2 marks] 13. List at least three file systems that you know. [2 marks] 14. In C programming, how the seek to a specific position in the file by offset? [2 marks]arrow_forwardA Personal Address Book application program allows the user to add, delete, search, save, and load contact information. The program separates the user interface (command-line) and the internal processing subsystem. The internal processing system consists of the following classes: • • Contact Manager (responsible for add and delete operations) Contact Finder (responsible for the search operation) pataManager (responsible for save and load operations) a. What design pattern can be used to implement the user interface? Explain your answer using a class diagram for the entire system. b. Draw a UML sequence diagram to show the behavioral view of the Personal Address Book program, demonstrating what happens when a user enters new contact information.arrow_forwardA system comprises three components: A, B, and C. Calling A requires calling B, and calling B requires calling A. Component C is responsible for dissimilar tasks T#1, #2, and T#3. a. Comment on the modifiability of this system. What problems do you see in this system, and how would you solve them? b. Suppose that T#1 is performed by both component A and C. What does this indicate about A and C? How would you solve this problem?arrow_forward
- Please answer questions from number 1 to 3 if these questions in the image provided below(NOTE: THESE QUESTIONS ARE NOT GRADED!)arrow_forwardIn a client-server system for a hypothetical banking application, the clients are ATM machines, and the server is the bank server. Suppose the client has two operations: withdraw and deposit. Use the broker architectural pattern to document an initial architecture design for this system: a. Draw a class diagram for this system. Use a client-side proxy to encrypt the data using an encrypt operation and a server-side proxy to decrypt the data. b. Discuss how you plan to apply redundancy tactics on the server. Additionally, identify the quality attribute that this tactic will achieve and discuss any potential side effects of applying it.arrow_forwarda. Comment on how you would achieve higher performance for a hypothetical Trent Course Registration System, assuming it utilizes a client-server architecture. b. Suppose we want greater availability of the server. Discuss what kind of tactics should be used to achieve that.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





