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) Do not work
together; no two people should have identical work!?!? 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 #5 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 dele.
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Β
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.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) Do not work
together; no two people should have identical work!?!? 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 #5 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);
2. 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;
3. 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;
4. 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;
}
5. 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);
6. 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;
7. 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;
8. 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)
{
9. 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< otherList; Suppose myList points to the list with the elements: 34 65 18 39 27 89 12 (in
this order). The statement: myList divideAt (otherList, 18) divides myList into two sublists:
myList points to the list with the elements 34 65, and otherList points to the sublist with the
elements 39 27 89 12. 6. b. Write the definition of the function to implement the tion divide
template a. Add o write a program to test your function. the following operation to the class
dered inkedli st opera-
Solution
Explanation :-
----------------------------
1.Take
nodeType *first1, *last1;
First and last for the divided list
2. Add Choice "6" for Divide
3.When user enter choice
Ask index where to break the list
10. When user enters the index , then break the list there
3) After User enters the index of item where to break the list
First find the item at the index
4)Check the method
/**
* first---> start of main list
* last ----> last of main list
* first1---> start of new list after list
* last1 ----> last of new listafter list
* item ---> item at which we have to split
*/
void breakList(nodeType*& first, nodeType*& last,nodeType*& first1, nodeType*&
last1,nodeType*item);
5)To break the list at middle , just give the middle index
Programme :-
----------------------------
#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);
//method to split the list
/**
* first---> start of main list
* last ----> last of main list
* first1---> start of new list after list
* last1 ----> last of new listafter list
11. * item ---> item at which we have to split
*/
void breakList(nodeType*& first, nodeType*& last,nodeType*& first1, nodeType*&
last1,nodeType*item);
int main()
{
nodeType *first, *last;
//First,Last for 2nd list after divide
nodeType *first1, *last1;
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. Divide
7. 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 , Divide
case 6:{
int index;
//Ask user item at which we need to divide
cout<<"Enter your index: ";
cin>>index;
//Go to item at given index , and then split
int i = 0;
nodeType *current = NULL;
current = first;
while (current != NULL)
12. {
current = current->link;
i++;
if(i == index){
break;
}
}
breakList(first,last,first1,last1,current);
}
break;
case 7: 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;
13. 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;
14. last->link= newNode;
last = newNode;
return;
}
void printList(nodeType*& first)
{
cout<<"Inside printList...printing linked list... "<info << " ";
current = current->link;
}
cout<link == item){
found = true;
break;
}
current = current->link;
}
//If item found
if(found){
//set first of new list
first1 = current->link;
//set last of new list
last1= last;
//set last of new list
last = current;
//close old list after current item
last->link = NULL;
}
}