Showing 1-3 out of 16
FE-May18-Sol.pdf-Page 1 of 4 Computer Science
FE-May18-Sol.pdf-Page 1 of 4 Computer Science
FE-May18-Sol.pdf-Page 1 of 4 Comput...
FE-May18-Sol.pdf-Page 1 of 4 Computer Science
Page 1
Page
1
of
4
Computer Science Foundation Exam
May 19, 2018
Section I A
DATA STRUCTURES
SOLUTION
NO books, notes, or calculators may be used,
and you must work entirely on your own.
Name:
___________________________________________
UCFID:
___________________________________________
NID:
Question #
Max Pts
Category
Score
1
5
DSN
2
10
DSN
3
10
ALG
TOTAL
25
----
You must do all 3 problems in this section of the exam.
Problems will be graded based on the completeness of the solution steps and not
graded based on the answer alone.
Credit cannot be given unless all work is shown
and is readable. Be complete, yet concise, and above all be neat. For each coding
question, assume that all of the necessary includes (stdlib, stdio, math, string) for that
particular question have been made.
Page 2
Summer 2018
Data Structures Exam, Part A
Page
2
of
4
1)
(5 pts) DSN (Dynamic Memory Management in C)
Suppose we have an array of structures containing information about our group for a group project.
Each
index should contain a group member’s name and phone number.
The structure is shown below: names
are stored as dynamically allocated strings and phone numbers are stored as integers.
When the semester
is over, we will delete this array.
Write a function called deleteGroup that will take in this array and delete
all the information, freeing all the memory space that the array previously took up.
Your function should
take 2 parameters: a pointer to the beginning of the array and an integer indicating the number of group
members.
It should return a null pointer representing the now empty array.
typedef struct GroupMember {
char *name;
int phoneNumber;
} GroupMember;
GroupMember* deleteGroup (GroupMember
*group, int numMembers) {
int i;
for(i=0; i<numMembers; i++)
//1 pt
free(group[i].name);
//2 pts
free(group);
//1 pt
return NULL;
//1 pt
}
Page 3
Summer 2018
Data Structures Exam, Part A
Page
3
of
4
2)
(10 pts) ALG (Linked Lists)
Suppose we have a linked list implemented with the structure below.
Write a function that will take in a
pointer to the head of list and inserts a node storing -1 after each even value in the list. If the list is empty
or there are no even values in the list, no modifications should be made to the list. (For example, if the
initial list had 2, 6, 7, 1, 3, and 8, the resulting list would have 2, -1, 6, -1, 7, 1, 8, -1.)
typedef struct node {
int data;
struct node* next;
} node;
void markEven(node *head) {
node* tmp = head;
while (tmp != NULL) {
// 2 pts iter whole list
while (tmp != NULL && tmp->data%2 != 0) //3pts find next even
tmp = tmp->next;
if (tmp != NULL) {
// 1 pt no null error
node* newnode = malloc(sizeof(node));
newnode->data = -1;
// 2 pts make new node
newnode->next = tmp->next;
// 2 pts patch it into
tmp->next = newnode;
// list
tmp = newnode;
}
}
}
Ace your assessments! Get Better Grades
Browse thousands of Study Materials & Solutions from your Favorite Schools
University of Pune
University_of_Pune
School:
Computer_Science_I
Course:
Introducing Study Plan
Using AI Tools to Help you understand and remember your course concepts better and faster than any other resource.
Find the best videos to learn every concept in that course from Youtube and Tiktok without searching.
Save All Relavent Videos & Materials and access anytime and anywhere
Prepare Smart and Guarantee better grades
Students also viewed documents
lab 18.docx
lab_18.docx
Course
Course
3
Module5QuizSTA2023.d...
Module5QuizSTA2023.docx.docx
Course
Course
10
Week 7 Test Math302....
Week_7_Test_Math302.docx.docx
Course
Course
30
Chapter 1 Assigment ...
Chapter_1_Assigment_Questions.docx.docx
Course
Course
5
Week 4 tests.docx.do...
Week_4_tests.docx.docx
Course
Course
23
Week 6 tests.docx.do...
Week_6_tests.docx.docx
Course
Course
106