80 likes | 226 Views
This document provides exercises focusing on linked lists and recursion in C programming. It includes tasks such as setting pointers to specific nodes, manipulating values of nodes, creating and inserting new nodes, deleting nodes, and implementing recursive functions. Each exercise requires practical coding that helps improve understanding of pointer manipulation in linked lists and base case identification in recursive functions. Ideal for beginners looking to enhance their programming skills in C.
E N D
44 NULL 87 43 16 23 32 25 Ch 5 Exercise 5 list A B a. Make A point to the node containing info 23 b. Make list point to the node containing info 16 c. Make B point to the last node on the list d. Make list point to an empty list e. Set the value of the node containing 25 to 35 f. Create and insert a node with info 10 after the node pointed to by A g. Delete the node with info 23 18
44 NULL 87 43 16 23 32 25 Chapter 5 Exercise 5 list A B a. Make A point to the node containing info 23 A = A->link; b. Make list point to the node containing info 16 list = list->link->link->link; c. Make B point to the last node on the list B=B->link->link; d. Make list point to an empty list list = NULL; e. Set the value of the node containing 25 to 35 B->link->info = 35 18
44 NULL 87 43 16 23 32 25 18 Chapter 5 Exercise 5 list A B f. Create and insert a node with info 10 after the node pointed to by A newNode= new nodeType; newNode→info=10; newNodelink = Alink->link; Alink = newNode g. Delete the node with info 23. temp=Alink; Alink=Alinklink; delete temp;
Chapter 6 Exercise 7 int mystery(int number) { if (number==0) return number; else return (number + mystery(number-1)); } a. base case? b. general case? c. mystery(0): 0 d. mystery(5) = 5+mystery(4) mystery(4)=4+mystery(3) mystery(3)= 3+mystery(2) mystery(2)=2+mystery(1) mystery(1)=1+mystery(0) = 1
Chapter 6 Exercise 7 int mystery(int number) { if (number==0) return number; else return (number + mystery(number-1)); } e. mystery(-5) = -5+mystery(-6) mystery(-6)=-6+mystery(-7) ...never reaches the base case
Chapter 6 Exercise 10 int test(int x, int y) { if (x==y) return x; else if (x>y) return (x+y); else return test(x+1, y-1); } test(5, 10) =? test(3, 19) =?