Docsity

Assignment 13 for Programming Using C - Fall 2007 | CGS 3460, Assignments of Computer Science

Toggle sidebar
bg1
CGS3460 Fall 2007
Assignment 13
Assigned: 11/28, Wed
Due: 12/5, Wed
1. Write a C program that sorts (ascending order) and displays a list of integers. Your program
must obtain a list of numbers from the user and then display the sorted list to the user. The user
indicates the end of input by entering a -1.
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
-1
1 2 3 4 5 6
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
pf3
pf4

Partial preview of the text

Download Assignment 13 for Programming Using C - Fall 2007 | CGS 3460 and more Assignments Computer Science in PDF only on Docsity!

CGS3460 Fall 2007

Assignment 13

Assigned: 11/28, Wed Due: 12/5, Wed

  1. Write a C program that sorts (ascending order) and displays a list of integers. Your program must obtain a list of numbers from the user and then display the sorted list to the user. The user indicates the end of input by entering a -1.

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.

  1. Write a C program that implements a doubly linked list. A doubly linked list is like a simple linked list except for the fact that the nodes in a doubly linked list have pointers which point to both the next and the previous node in the list. The advantage of having such a linked list is that, traversal in both forward and reverse direction in equally easy.

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

  1. First compress your program files into a single file. At the terminal command prompt (Putty incase you are working from Windows) type tar cvf assign13.tar p1.c p2.c. This should create the compressed file assign13.tar
  2. If you are working from Windows platform using Putty and WinSCP, you can transfer the tar file back to your Windows machine using WinSCP. It is reverse of the process you probably used to transfer your program(s) from your local machine to CISE machine.
  3. Upload the assign13.tar to CourseWorX at the course webpage.