Difference between revisions of "CSC270 Final Exam 2016"

From dftwiki3
Jump to: navigation, search
Line 12: Line 12:
 
<br />
 
<br />
 
=Problem 1=
 
=Problem 1=
 +
<br />
 +
The program below implements a list of pairs of ints.  A linked list is first created using ints from an array, and then the list is displayed, highlighting the pairs.
 
<br />
 
<br />
 
::<source lang="C" highlight="40,41">
 
::<source lang="C" highlight="40,41">
Line 73: Line 75:
 
<br />
 
<br />
 
::<source lang="C">
 
::<source lang="C">
   int*  table = table1;  // array                                                                                   
+
   int*  table = table2;  // array                                                                                   
   int  N    = N1;      // dimension of array                                                                       
+
   int  N    = N2;      // dimension of array                                                                       
 +
</source>
 +
<br />
 +
* Compile and run the program, and verify that it displays the list of pairs.  Make sure you understand how it works.
 +
<br />
 +
==Your Assignment==
 +
<br />
 +
Add a function called '''removePair()''' to the program.  This function will remove all pairs/nodes from the linked list where the first element of the pair is larger than the second element of the pair.  For example, if the list is initially displayed as
 +
<br />
 +
::<source lang="text">
 +
List = (11, 9) (7, 35) (5, 15) (2, 20) (1, 10)
 +
</source>
 +
<br />
 +
Then after calling the function '''removePair()''', the list should display as:
 +
::<source lang="text">
 +
List =  (7, 35) (5, 15) (2, 20) (1, 10)
 +
</source>
 +
<br />
 +
'''RemovePair()''' will have removed (11, 9) from the list since 11 is larger than 9.
 +
<br />
 +
If several pairs exist that have the first item larger than the second one, then '''removePair()''' will remove all of them.
 +
<br />
 +
==Expected Output==
 +
<br />
 +
Your program should output the original linked list, followed by the list with the "bad" pairs removed.
 +
<br />
 +
:<source lang="text">
 +
Example:
 +
List = (11, 9) (7, 35) (5, 15) (2, 20) (1, 10)
 +
List = (7, 35) (5, 15) (2, 20) (1, 10)
 
</source>
 
</source>
 
 
<br />
 
<br />
 
=Problem 2=
 
=Problem 2=

Revision as of 17:04, 19 April 2016

--D. Thiebaut (talk) 10:09, 16 April 2016 (EDT)


...