Esc101: Fundamentals of Computing Esc101: Fundamentals of Computing
Esc101: Fundamentals of Computing Esc101: Fundamentals of Computing
Esc101: Fundamentals of Computing Esc101: Fundamentals of Computing
Announcements
Last date for course drop is 20th October. p
I will sign drop requests till 19th October.
Lec-26
Recap
Modular programming p g g
divide problem into smaller problems write a separate function for each sub-problem
Lec-26
Typedef
User defined types can be given names
struct point { float x; float y; }; typedef struct point Point;
Now we can use Point (note capital P) as a type in addition to struct point (note small p)
Lec-26 Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon 4
Typedef
We can declare variables in either of the following ways:
Point p1, p1 p2; struct point p3, p4;
struct point { x; y;
Typedef
typedef can also be used to define types other than structures:
typedef yp Height typedef Letters typedef Natural float h1; Height; g ; // same as float h1, but more intuitive
Lec-26
Unnamed Structures
A structure need not be named, if it is not used to declare variables: struct student { int roll; char *name; struct { int quizzes; int labs; int midsem; int endsem; } esc101, mth101; } s; s.esc101.midsem = 55;
Lec-26 Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon 7
Self-referential Structures
A structure having a member of the type pointer to the same structure
struct student { int roll; char *name; struct student *next; };
Lec-26
Linked List
A linked list is a chain of self referential structures self-referential Each node contains some data, and a pointer to the next such node One creates as many such nodes as necessary to store available information The beginning of such a list is maintained as a pointer to the fi t d ( th first node (generally called head) ll ll d h d)
Lec-26
Linked Lists
Dynamic data structure
Size of the linked list grows or shrinks during the execution of a program
Advantages:
Asks for only as much memory allocation as needed during any stage of the execution Provides flexibility in inserting and deleting elements by just re-arranging the links
Disadvantage:
Accessing a particular element (searching) is not easy
Lec-26
10
Linked Lists
Three major operations on linked lists:
Insertion Delete Searching
Lec-26
11
Any Questions?
Lec-26
12