1 / 6

Linked List and Recursion Exercises in C Programming

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.

Download Presentation

Linked List and Recursion Exercises in C Programming

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. 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

  2. 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

  3. 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; newNodelink = Alink->link; Alink = newNode g. Delete the node with info 23. temp=Alink; Alink=Alinklink; delete temp;

  4. 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

  5. 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

  6. 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) =?

More Related