









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Sedgewick Program 5.
Sedgewick Program 5.
int count(link x) { if (x == NULL) return 0; return 1 + count(x->next); } void traverse(link h, void (visit)(link)) { if (h == NULL) return; (visit)(h); traverse(h->next, visit); } Sedgewick Program 5.
void traverseR(link h, void (visit)(link)) { if (h == NULL) return; traverseR(h->next, visit); (visit)(h); } link delete(link x, Item v) { /* Delete a nodes, and returns remainder of list */ if (x == NULL) return NULL; if (eq(x->item, v)) { link t = x->next; free(x); return t; } x->next = delete(x->next, v); return x; } Sedgewick Program 5.
A more common example of recursion is searching through a hard disk directory structure. Analysis:
usingImplementation of Directory Search System; using System.IO; namespace RecursiveDirectoryFileSearch { class RecursiveDirectoryFileSearch { static void main(string[] args) { Console.WriteLine("Found {0} occurrences.", iDirectorySearch(@"C:","*.tmp")); Console.WriteLine( "Press enter to continue"); Console.ReadLine(); } } } This implementation is in C#.