SlideShare a Scribd company logo
Assignment is:
"Page 349-350 #4 and #5 Use the "Linked List lab" you have been working on in class and add
the two functions the questions are asking you to develop: divideMid and divideAt. Be sure to
include comments Use meaningful identifier names (constants where appropriate) Turn in .cpp
file AND Turn in a "print-screen' of your output (press "print-screen' on keyboard, then
'paste' in MS-Word)"
How do you solve QUESTION #4 in the book data structures using c++ by D.S. Malik in Visiual
Studios using the linked list below with what is being asked? Please need help
Linked list :
#include
#include
using namespace std;
struct nodeType
{
int info;
nodeType *link;
};
void createList(nodeType*& first, nodeType*& last);
void printList(nodeType*& first);
void insertFront(nodeType*& first);
void insertBack(nodeType*& last);
void deleteFirst(nodeType*& first);
void deleteLast(nodeType*& last, nodeType* first);
int main()
{
nodeType *first, *last;
int num;
createList(first, last);
int choice;
while(true)
{
cout<<"1. Insert Front. 2. Insert Last. 3. Delete Front. 4. Delete Last. 5. Print List. 6. Exit.
";
cout<<"Enter your choice: ";
cin>>choice;
switch(choice)
{
case 1: insertFront(first); break;
case 2: insertBack(last); break;
case 3: deleteFirst(first); break;
case 4: deleteLast(last, first); break;
case 5: printList(first); break;
case 6: return 0;
default: cout<<"Invalid menu option. Try again."<>number;
while (number != -999)
{
newNode = new nodeType; // create new node
newNode->info = number;
newNode->link = NULL;
if (first == NULL)
{
first = newNode;
last = newNode;
}
else
{
last->link = newNode;
last = newNode;
}
cout<<"Enter an integer (-999 to stop): ";
cin>>number;
} // end of while-loop
} // end of build list function
void deleteFirst(nodeType*& first)
{
nodeType *temp;
temp= first;
first= temp->link;
delete temp;
return;
}
void deleteLast(nodeType*& last, nodeType* current)
{
nodeType *temp;
while(current->link != NULL)
{
temp=current;
current=current->link;
}
temp=last;
current->link=NULL;
delete temp;
last = current;
return;
}
void insertFront(nodeType*& front)
{
int num;
cout<<" Enter the number to insert: ";
cin>>num;
nodeType *newNode = new nodeType;
newNode->info=num;
newNode->link= front;
front= newNode;
return;
}
void insertBack(nodeType*& last)
{
int num;
cout<<" Enter the number to insert: ";
cin>>num;
nodeType *newNode = new nodeType;
newNode->info=num;
newNode->link= NULL;
last->link= newNode;
last = newNode;
return;
}
void printList(nodeType*& first)
{
cout<<"Inside printList...printing linked list... "<info << " ";
current = current->link;
}
cout<
#include
using namespace std;
struct nodeType
{
int info;
nodeType *link;
};
void createList(nodeType*& first, nodeType*& last);
void printList(nodeType*& first);
void insertFront(nodeType*& first);
void insertBack(nodeType*& last);
void deleteFirst(nodeType*& first);
void deleteLast(nodeType*& last, nodeType* first);
int main()
{
nodeType *first, *last;
int num;
createList(first, last);
int choice;
while(true)
{
cout<<"1. Insert Front. 2. Insert Last. 3. Delete Front. 4. Delete Last. 5. Print List. 6. Exit.
";
cout<<"Enter your choice: ";
cin>>choice;
switch(choice)
{
case 1: insertFront(first); break;
case 2: insertBack(last); break;
case 3: deleteFirst(first); break;
case 4: deleteLast(last, first); break;
case 5: printList(first); break;
case 6: return 0;
default: cout<<"Invalid menu option. Try again."<>number;
while (number != -999)
{
newNode = new nodeType; // create new node
newNode->info = number;
newNode->link = NULL;
if (first == NULL)
{
first = newNode;
last = newNode;
}
else
{
last->link = newNode;
last = newNode;
}
cout<<"Enter an integer (-999 to stop): ";
cin>>number;
} // end of while-loop
} // end of build list function
void deleteFirst(nodeType*& first)
{
nodeType *temp;
temp= first;
first= temp->link;
delete temp;
return;
}
void deleteLast(nodeType*& last, nodeType* current)
{
nodeType *temp;
while(current->link != NULL)
{
temp=current;
current=current->link;
}
temp=last;
current->link=NULL;
delete temp;
last = current;
return;
}
void insertFront(nodeType*& front)
{
int num;
cout<<" Enter the number to insert: ";
cin>>num;
nodeType *newNode = new nodeType;
newNode->info=num;
newNode->link= front;
front= newNode;
return;
}
void insertBack(nodeType*& last)
{
int num;
cout<<" Enter the number to insert: ";
cin>>num;
nodeType *newNode = new nodeType;
newNode->info=num;
newNode->link= NULL;
last->link= newNode;
last = newNode;
return;
}
void printList(nodeType*& first)
{
cout<<"Inside printList...printing linked list... "<info << " ";
current = current->link;
}
cout< my List; unorderedLinkedListkint subList; Suppose myList points to the list with elements
34 65 27 89 12 lin this order). The statement: myList divide Mid (subList) divides myList into
two sublists: myList points to the list with the elements 34 65 27, and ist points to the sublist
with the elements 89 12. b. Write the definition of the function template to implement the o tion
divideMid. Also write a program to test your function.
Solution
//following code will help you to solve your problem
/*make sure that you incorporate this into your piece of code along with necessary change like
adding the option for this function as well into your options list of tasks*/
template
void linkedListType:divideMid(linkedListType &sublist)
{
int myListItems, subListItems;
if ((count%2)!=0) myListItems = (count/2 + 1);
else myListItems = (count/2);
subListItems = (count - myListItems);
nodeType *current;
current = first;
sublist.last = last;
for (int i=0; i link; //traverses the list until it gets to where it must divde.
}
last->link=NULL; //cuts off myList in the middle
sublist.first = current; //assigns the next node to sublist.first.
}

More Related Content

PDF
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
PDF
In the class we extensively discussed a node class called IntNode in.pdf
PDF
This assignment and the next (#5) involve design and development of a.pdf
PDF
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
DOCX
C++ Please write the whole code that is needed for this assignment- wr.docx
PDF
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
PDF
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
PDF
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
In the class we extensively discussed a node class called IntNode in.pdf
This assignment and the next (#5) involve design and development of a.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf

Similar to Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf (20)

PDF
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
PDF
Lec-4_Linked-List (1).pdf
PDF
In C++Write a recursive function to determine whether or not a Lin.pdf
DOCX
Linked lists
PDF
Need to be done in C++ Please Sorted number list implementation wit.pdf
PPT
linked-list.ppt
PPTX
Data Structures - Lecture 7 [Linked List]
PDF
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
PDF
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
PDF
Need to be done in C Please Sorted number list implementation with.pdf
PPT
Mi 103 linked list
PPTX
Linked lists in Data Structure
PPTX
3.linked list
PDF
Please need help on following program using c++ language. Please inc.pdf
PDF
Please help solve this in C++ So the program is working fin.pdf
PPT
dynamicList.ppt
PDF
#includeiostream #includecstdio #includecstdlib using na.pdf
PPTX
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
PPTX
Lecture 4 data structures and algorithms
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Lec-4_Linked-List (1).pdf
In C++Write a recursive function to determine whether or not a Lin.pdf
Linked lists
Need to be done in C++ Please Sorted number list implementation wit.pdf
linked-list.ppt
Data Structures - Lecture 7 [Linked List]
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need to be done in C Please Sorted number list implementation with.pdf
Mi 103 linked list
Linked lists in Data Structure
3.linked list
Please need help on following program using c++ language. Please inc.pdf
Please help solve this in C++ So the program is working fin.pdf
dynamicList.ppt
#includeiostream #includecstdio #includecstdlib using na.pdf
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
Lecture 4 data structures and algorithms
Ad

More from fortmdu (20)

PDF
How is a Decision Support Systems (DSS) different from a Management .pdf
PDF
I am trying to create a program That works with two other programs i.pdf
PDF
How does anti-malware software detect virusesWhat techniques are .pdf
PDF
How can I upload a picture in here I tried with image properties ic.pdf
PDF
Explain the role of ATP in the action of Hsp70 and GroELES.Solu.pdf
PDF
Files Please respond to the following •Suppose you are creating.pdf
PDF
evil_server.cpp#include string #include cstdlib #include.pdf
PDF
ecorrect Question 32 0 1 pts Referencing the diagram above, use the .pdf
PDF
Disneys Expedition EverestOne of the newest thrill rides to open.pdf
PDF
Discuss ONE risk that a company faces when trying to diversify inte.pdf
PDF
Describe at least one reason why transitioning from PVST+ to Rapid P.pdf
PDF
CASE 2-1 BUILDING UP OUR ASSETS DHR CONSTRUCTIONIn August 2011, w.pdf
PDF
C++ Write a function that takes two numbers are parameters and retu.pdf
PDF
B.1 Reaction of a Hydrate Addition of Water (2) Appearance Heating (1.pdf
PDF
You maintain several virtual machines (VMs) in an offline state. How.pdf
PDF
Which of the following statements is not TRUE1)For a 64-bit compute.pdf
PDF
You are running an ELISA on a sample to test for the presence of .pdf
PDF
You are to write an efficient program that will read a dictionary of.pdf
PDF
X = C B - B C D; Use Accumulator Register-Register (LoadSt.pdf
PDF
Tic-Tac-Toe Simulator [C# Visual Basic] Create an application th.pdf
How is a Decision Support Systems (DSS) different from a Management .pdf
I am trying to create a program That works with two other programs i.pdf
How does anti-malware software detect virusesWhat techniques are .pdf
How can I upload a picture in here I tried with image properties ic.pdf
Explain the role of ATP in the action of Hsp70 and GroELES.Solu.pdf
Files Please respond to the following •Suppose you are creating.pdf
evil_server.cpp#include string #include cstdlib #include.pdf
ecorrect Question 32 0 1 pts Referencing the diagram above, use the .pdf
Disneys Expedition EverestOne of the newest thrill rides to open.pdf
Discuss ONE risk that a company faces when trying to diversify inte.pdf
Describe at least one reason why transitioning from PVST+ to Rapid P.pdf
CASE 2-1 BUILDING UP OUR ASSETS DHR CONSTRUCTIONIn August 2011, w.pdf
C++ Write a function that takes two numbers are parameters and retu.pdf
B.1 Reaction of a Hydrate Addition of Water (2) Appearance Heating (1.pdf
You maintain several virtual machines (VMs) in an offline state. How.pdf
Which of the following statements is not TRUE1)For a 64-bit compute.pdf
You are running an ELISA on a sample to test for the presence of .pdf
You are to write an efficient program that will read a dictionary of.pdf
X = C B - B C D; Use Accumulator Register-Register (LoadSt.pdf
Tic-Tac-Toe Simulator [C# Visual Basic] Create an application th.pdf
Ad

Recently uploaded (20)

PDF
Basic Mud Logging Guide for educational purpose
PPTX
master seminar digital applications in india
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Cell Structure & Organelles in detailed.
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Institutional Correction lecture only . . .
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Pre independence Education in Inndia.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Lesson notes of climatology university.
PDF
Sports Quiz easy sports quiz sports quiz
Basic Mud Logging Guide for educational purpose
master seminar digital applications in india
2.FourierTransform-ShortQuestionswithAnswers.pdf
Computing-Curriculum for Schools in Ghana
Cell Structure & Organelles in detailed.
Pharma ospi slides which help in ospi learning
Final Presentation General Medicine 03-08-2024.pptx
TR - Agricultural Crops Production NC III.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
STATICS OF THE RIGID BODIES Hibbelers.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Institutional Correction lecture only . . .
Microbial disease of the cardiovascular and lymphatic systems
Pre independence Education in Inndia.pdf
Supply Chain Operations Speaking Notes -ICLT Program
PPH.pptx obstetrics and gynecology in nursing
Lesson notes of climatology university.
Sports Quiz easy sports quiz sports quiz

Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf

  • 1. Assignment is: "Page 349-350 #4 and #5 Use the "Linked List lab" you have been working on in class and add the two functions the questions are asking you to develop: divideMid and divideAt. Be sure to include comments Use meaningful identifier names (constants where appropriate) Turn in .cpp file AND Turn in a "print-screen' of your output (press "print-screen' on keyboard, then 'paste' in MS-Word)" How do you solve QUESTION #4 in the book data structures using c++ by D.S. Malik in Visiual Studios using the linked list below with what is being asked? Please need help Linked list : #include #include using namespace std; struct nodeType { int info; nodeType *link; }; void createList(nodeType*& first, nodeType*& last); void printList(nodeType*& first); void insertFront(nodeType*& first); void insertBack(nodeType*& last); void deleteFirst(nodeType*& first);
  • 2. void deleteLast(nodeType*& last, nodeType* first); int main() { nodeType *first, *last; int num; createList(first, last); int choice; while(true) { cout<<"1. Insert Front. 2. Insert Last. 3. Delete Front. 4. Delete Last. 5. Print List. 6. Exit. "; cout<<"Enter your choice: "; cin>>choice; switch(choice) { case 1: insertFront(first); break; case 2: insertBack(last); break; case 3: deleteFirst(first); break; case 4: deleteLast(last, first); break; case 5: printList(first); break; case 6: return 0; default: cout<<"Invalid menu option. Try again."<>number; while (number != -999) { newNode = new nodeType; // create new node newNode->info = number; newNode->link = NULL;
  • 3. if (first == NULL) { first = newNode; last = newNode; } else { last->link = newNode; last = newNode; } cout<<"Enter an integer (-999 to stop): "; cin>>number; } // end of while-loop } // end of build list function void deleteFirst(nodeType*& first) { nodeType *temp; temp= first; first= temp->link;
  • 4. delete temp; return; } void deleteLast(nodeType*& last, nodeType* current) { nodeType *temp; while(current->link != NULL) { temp=current; current=current->link; } temp=last; current->link=NULL; delete temp; last = current; return; } void insertFront(nodeType*& front) { int num; cout<<" Enter the number to insert: "; cin>>num; nodeType *newNode = new nodeType; newNode->info=num; newNode->link= front; front= newNode; return; } void insertBack(nodeType*& last) {
  • 5. int num; cout<<" Enter the number to insert: "; cin>>num; nodeType *newNode = new nodeType; newNode->info=num; newNode->link= NULL; last->link= newNode; last = newNode; return; } void printList(nodeType*& first) { cout<<"Inside printList...printing linked list... "<info << " "; current = current->link; } cout< #include using namespace std; struct nodeType { int info; nodeType *link; }; void createList(nodeType*& first, nodeType*& last); void printList(nodeType*& first); void insertFront(nodeType*& first); void insertBack(nodeType*& last); void deleteFirst(nodeType*& first); void deleteLast(nodeType*& last, nodeType* first);
  • 6. int main() { nodeType *first, *last; int num; createList(first, last); int choice; while(true) { cout<<"1. Insert Front. 2. Insert Last. 3. Delete Front. 4. Delete Last. 5. Print List. 6. Exit. "; cout<<"Enter your choice: "; cin>>choice; switch(choice) { case 1: insertFront(first); break; case 2: insertBack(last); break; case 3: deleteFirst(first); break; case 4: deleteLast(last, first); break; case 5: printList(first); break; case 6: return 0; default: cout<<"Invalid menu option. Try again."<>number; while (number != -999) { newNode = new nodeType; // create new node newNode->info = number; newNode->link = NULL; if (first == NULL)
  • 7. { first = newNode; last = newNode; } else { last->link = newNode; last = newNode; } cout<<"Enter an integer (-999 to stop): "; cin>>number; } // end of while-loop } // end of build list function void deleteFirst(nodeType*& first) { nodeType *temp; temp= first; first= temp->link; delete temp; return;
  • 8. } void deleteLast(nodeType*& last, nodeType* current) { nodeType *temp; while(current->link != NULL) { temp=current; current=current->link; } temp=last; current->link=NULL; delete temp; last = current; return; } void insertFront(nodeType*& front) { int num; cout<<" Enter the number to insert: "; cin>>num; nodeType *newNode = new nodeType; newNode->info=num; newNode->link= front; front= newNode; return; } void insertBack(nodeType*& last) { int num; cout<<" Enter the number to insert: ";
  • 9. cin>>num; nodeType *newNode = new nodeType; newNode->info=num; newNode->link= NULL; last->link= newNode; last = newNode; return; } void printList(nodeType*& first) { cout<<"Inside printList...printing linked list... "<info << " "; current = current->link; } cout< my List; unorderedLinkedListkint subList; Suppose myList points to the list with elements 34 65 27 89 12 lin this order). The statement: myList divide Mid (subList) divides myList into two sublists: myList points to the list with the elements 34 65 27, and ist points to the sublist with the elements 89 12. b. Write the definition of the function template to implement the o tion divideMid. Also write a program to test your function. Solution //following code will help you to solve your problem /*make sure that you incorporate this into your piece of code along with necessary change like adding the option for this function as well into your options list of tasks*/ template void linkedListType:divideMid(linkedListType &sublist) { int myListItems, subListItems; if ((count%2)!=0) myListItems = (count/2 + 1); else myListItems = (count/2); subListItems = (count - myListItems);
  • 10. nodeType *current; current = first; sublist.last = last; for (int i=0; i link; //traverses the list until it gets to where it must divde. } last->link=NULL; //cuts off myList in the middle sublist.first = current; //assigns the next node to sublist.first. }