


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Assigned: 11/28, Wed Due: 12/5, Wed
You are provided a header file called temp.h which has declaration of a constant MAX_NUM which govern the maximum number of integers user is allowed to enter and a function declaration
int larger(int,int).
You must define this function in a file called temp.c such that it takes two integer arguments and return the larger integer of the two. You must then use this function in your sorting implementation, possibly while comparing two entries of the array to be swapped. Note that you are not allowed to have another function with the same name in your sorting application. temp.c should not have any function other than one indicated above and you must save your rest of the code in a file called p1.c. So your code will be divided into three files, temp.h, temp.c and p1.c.
Further, for displaying all the messages in your program, you are only allowed to used macros, so define and use macros as needed.
Example 1: 6 5 4 3 2 1
Example 2: 9 8 7 65 23 12334 34 5 3 2 1 Exceeded maximum array size 2 3 5 7 8 9 23 34 65 12334
[Note that in case the user exceeds the maximum allowed number of integers (MAX_NUM), appropriate message is displayed, and only the first MAX_NUM numbers are sorted. In this particular example MAX_NUM was set to 10. You must match this behavior of the program.
For this exercise, assume that each node in the list can store an integer. Your program should be menu driven and should allow user to add nodes to the list, display them while traversing the list in forward direction, display them while traversing the list in reverse direction and exit the program. (See examples)
To implement this program, most of the required machinery is present in the class notes. The only additions would be an extra pointer in the node structure (to point to previous node in the list) and possibly a pointer to keep track of the last node in the list (like the first node). You must take care of the fact the when an addition (always at the end of the list) is made to the list, both next pointer of the current last node and the previous pointer of the new node should be carefully updated.
Save your program in a file called p2.c. If you do this problem correctly, you can score 30% bonus points on this assignment.
Example 1. Enter 1 to add a node Enter 2 to display the list in forward order Enter 3 to display the list in reverse order Enter 4 to exit Enter choice: 1 Enter a number: 10 Node created Enter 1 to add a node Enter 2 to display the list in forward order Enter 3 to display the list in reverse order Enter 4 to exit Enter choice: 2 10 Enter 1 to add a node Enter 2 to display the list in forward order Enter 3 to display the list in reverse order Enter 4 to exit Enter choice: 3 10 Enter 1 to add a node Enter 2 to display the list in forward order Enter 3 to display the list in reverse order Enter 4 to exit Enter choice: 4
[Note the message displayed after creation of each node]
Enter 3 to display the list in reverse order Enter 4 to exit Enter choice: 3 30 20 10 Enter 1 to add a node Enter 2 to display the list in forward order Enter 3 to display the list in reverse order Enter 4 to exit Enter choice: 1 Enter a number: 40 Node created Enter 1 to add a node Enter 2 to display the list in forward order Enter 3 to display the list in reverse order Enter 4 to exit Enter choice: 3 40 30 20 10 Enter 1 to add a node Enter 2 to display the list in forward order Enter 3 to display the list in reverse order Enter 4 to exit Enter choice: 1 Enter a number: 50 Node created Enter 1 to add a node Enter 2 to display the list in forward order Enter 3 to display the list in reverse order Enter 4 to exit Enter choice: 2 10 20 30 40 50 Enter 1 to add a node Enter 2 to display the list in forward order Enter 3 to display the list in reverse order Enter 4 to exit Enter choice: 4
Instructions for submitting Assignment 13