In C++

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

In C++

Post by answerhappygod »

In C++
In C 1
In C 1 (93.71 KiB) Viewed 8 times
Implement a Double LinkedList class which can store integers in a sorted order. This class will implement the following functions: 1. Constructor will create an empty list. 2. Get current size function will return the number of items in the list. 3. Is empty function will return true if the list is empty. 4. Clear function will remove all the items from the list. 5. Find function will find the given item in the list. 6. Add function will add a new item to the list. 7. Remove function will remove an item from the list. 8. Print function will display the list of items. Notes: 1. You do not have to implement a Template class as your linked list will only store integer data. 2. Add function must maintain the order of items in the list. For example if your list has the following items: 2, 4, 6, 8, 10, 12 and you want to add a 7 then the add function in the linked list class will traverse through the list to find the correct location for 7 (which is between 6 and 8) and it will add new node with 7 between the nodes with 6 and 8. After the addition of 7 the list will be as follows: 2, 4, 6, 7, 8, 10, 12 3. Remove function must maintain the order of items in the list. For example if your list has the following items: 2, 4, 6, 8, 10, 12 and you want to remove 8 then the remove function in the linked list class will traverse through the list to find the node with 8 and it will remove the node which contains 8. After the removal of the 8 the list will be as follows: 2, 4, 6, 10, 12. It must also delete the removed node. 4. Clear function must delete all the nodes in the list.
Write a main function to show that your linked list class works as specified. Your main function will test your linked list class by completing the following steps: 1. It will create a linked list object. 2. It will add 1 to the list. 3. It will add 5 to the list. 4. It will add 9 to the list. 5. It will add 16 to the list 6. It will add 25 to the list. 7. It will add 2 to the list. 8. It will add 7 to the list. 9. It will add 19 to the list. 10. It will display the list using the print function. The output will be as follows: 1 2 5 7 9 16 19 25 11. It will use the add function to add 10 to the list. 12. It will display the list on the screen using the print function. The output will be as follows: 1 2 5 7 9 10 16 19 25 13. It will use the current size function to get the number of items in the list and will display the result. The output will be as follows: Number of items in the list is: 9 14. It will use the is empty function to check if the list is empty and will display the result. The output will be as follows: List is not empty. 15. It will use the remove function to remove 9 from the list. 16. It will display the list on the screen using the print function. The output will be as follows: 1 2 5 7 10 16 19 25 17. It will use the current size function to get the number of items in the list and will display the result. The output will be as follows: Number of items in the list is: 8 18. It will use the find function to find the location (index number) of 16 and display the result. The output will be as follows: Number 16 is located at position 5. 19. It will use the find function to find the location (index number) of 9 and display the result. The output will be as follows: Number 9 is not in the list. 20. It will use the clear function to remove all items from the list. 21. It will use the is empty function to check if the list is empty and will display the result. The output will be as follows: List is empty.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply