1 / 11

Lab Session 6

COP 3502 Spring 2005 Christopher Elwell. Lab Session 6. Administrivia. Recitation notes duplicated online: http://www.cs.ucf.edu/~celwell Office Hours MTWF 2-4 PM Assignment 1 Discussion Grades should be posted by 2/17/05. Queues. FIFO (First In-First Out) data structure

takara
Download Presentation

Lab Session 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COP 3502 Spring 2005 Christopher Elwell Lab Session 6

  2. Administrivia • Recitation notes duplicated online: • http://www.cs.ucf.edu/~celwell • Office Hours • MTWF 2-4 PM • Assignment 1 Discussion • Grades should be posted by 2/17/05

  3. Queues • FIFO (First In-First Out) data structure • Has head and tail pointers • Always enqueue at tail • Always dequeue at head • Can be implemented as a “circular array”

  4. Queues • Consider a queue of size 12 using the “circular array” implementation. Indicate the number of empty slots when • Front =-1 and rear=-1 • Front = 0 and rear = 11 • Front = 9 and rear = 11 • Front = 3 and rear = 3

  5. Queues • Consider a queue of size 12 using the “circular array” implementation. Indicate the number of empty slots when • Front =-1 and rear=-1 12 • Front = 0 and rear = 11 0 • Front = 9 and rear = 11 9 • Front = 3 and rear = 3 11

  6. Recursion • Write a recursive function which takes a positive number and returns the sum of its digits. For example, digitsum(2304) returns 2+3+0+4=9.

  7. Recursion int digitsum(int n){ if (n==0) return 0; else return (n%10+digitsum(n/10)); }

  8. Recursion 2 • Write a recursive function int sum() that takes in an integer array and the number of items in the array and returns the summation of all items in the array.

  9. int sum (int L[], int n){ if (n==0) return 0; else return (L[1]+sum(L+1, n-1)); } Recursion 2

  10. Recursion 3 • Write a recursive function that prints out the characters of a string in reverse order.

  11. void print_reverse(char *ptr){ if (*ptr=='\0') return; print_reverse(ptr+1); printf(“%c”, *ptr); } Recursion 3

More Related