SlideServe
Menu
Préférences
© SlideServe · v2026

Introduction to Queues and Recursion in Programming

takara avatar
11 diapositives · 239 Views · Sep 14, 2014

This lab session focuses on the essential concepts of queues and recursion in computer science. We explore the FIFO (First In-First Out) principle of queues, including their implementation as circular arrays. Participants will examine various scenarios to calculate the number of empty slots based on different front and rear positions in a queue of size 12. Additionally, we discuss recursive functions to compute the sum of digits, total items in an integer array, and print characters of a string in reverse order. Important office hours and assignment details are also included.

Introduction to Queues and Recursion in Programming - slide 1
01 / 11Introduction to Queues and Recursion in Programming
1 / 17

Télécharger la présentation

Introduction to Queues and Recursion in Programming
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  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