CS112_33_Slides-ListADT

CS112_33_Slides-ListADT - CS112 Fundamentals of Programming...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS112 Fundamentals of Programming Abstractions Recursive List Yinglin Wang CS Dept., SJTU CS112 Fundamentals of Programming Abstractions Processing Recursive Data Structures When we design recursive data structures, we generally write recursive functions to process them. The recursive code is easy, because the way the function works is a direct reflection of the way the data structure is designed. CS112 Fundamentals of Programming Abstractions Processing Recursive Data Structures Here is an example. With this definition of a cellT, we would expect a lot of functions that work with lists of cellT's to look like the pseudocode shown. (text page 509) CS112 Fundamentals of Programming Abstractions listADT Today we will turn our notion of a singly linked list into an ADT. In this case the CDT itself is recursive. It contains a listADT, which is a pointer to a listCDT. (text page 511-512) CS112 Fundamentals of Programming Abstractions The result in memory is that we can build singly linked lists in the usual way. element1 element2 element3 list typedef struct listCDT *listADT; struct listCDT { listElementT head; listADT tail; }; CS112 Fundamentals of Programming Abstractions If we advance along a list with a statement like list = list->tail , what will eventually happen? element1 element2 element3 list typedef struct listCDT *listADT; struct listCDT { listElementT head; listADT tail; }; CS112 Fundamentals of Programming Abstractions After the first execution of list = list->tail element1 element2 element3 list typedef struct listCDT *listADT; struct listCDT { listElementT head; listADT tail; }; CS112 Fundamentals of Programming Abstractions After the second execution of list = list->tail element1 element2 element3 list typedef struct listCDT *listADT; struct listCDT { listElementT head; listADT tail; }; CS112 Fundamentals of Programming Abstractions After the third execution of list = list->tail element1 element2 element3 list typedef struct listCDT *listADT; struct listCDT...
View Full Document

Page1 / 15

CS112_33_Slides-ListADT - CS112 Fundamentals of Programming...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online