Exam3doc - Exam 3 ECS 102 Spring 2006 Dr. Baruch 1 2 3 4 5...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Exam 3 ECS 102 Spring 2006 Dr. Baruch 1 8 2 10 3 12 4 8 5 10 6 8 7 10 8 8 9 8 10 10 11 4 12 4 total 100
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1. /* a declaration in main */ int list[10] = { 2, 4, 6, 8 }; /* swapA */ void swapA(int * x, int * y) { int temp; temp=*x; *x = *y; *y = temp; } /* swapB */ void swapB(int s[ ],int i, int j) { int temp; temp=s[i]; s[i]=s[j]; s[j]=temp; } A. Write a function call that uses swapA to interchange the second and third elements of list . Example: Before: list After: list B. Write a function call that uses swapB to interchange the first and fourth elements of list . Example: Before: list After: list 2 4 6 8 0 0 0 0 0 0 2 6 4 8 0 0 0 0 0 0 2 6 4 8 0 0 0 0 0 0 8 6 4 2 0 0 0 0 0 0
Background image of page 2
2. Write the definition of a function void sort( double arr[ ], int num_items); that will put an array of double into ascending order. Example: Before: arr After: arr 5.2 4.1 3.1 9.9 0.02 13.5 junk junk junk junk 0.02 3.1 4.1 5.2 9.9 13.5 junk junk junk junk
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3. int insert(int list[ ], int to, /* index where val should go */ int val, /* value to be inserted */ int *num_items, /* current number of items in list */ int max_num_items) /* maximum number of items list can hold */ { int i; if (*num_items >= max_num_items) { printf("No more room."); return 0; } if (to > (*num_items+1))
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

Exam3doc - Exam 3 ECS 102 Spring 2006 Dr. Baruch 1 2 3 4 5...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online