Sei sulla pagina 1di 7

ESc101: Fundamentals of Computing

2011-12-Monsoon Semester Lecture #26, October 10, 2011

Please switch off your mobile phones.

Announcements
Last date for course drop is 20th October. p
I will sign drop requests till 19th October.

Friday Lab Section please note


Lab on 14th suspended due to Gymkhana Holiday for Antaragni It will be conducted on 18th (Tuesday) If anyone from Friday Lab sections has a class/lab/tutorial on f F id L b ti h l /l b/t t i l Tuesday afternoon, please let us know by noon time TODAY.

Tuesday Lab Section please note


10th lab on Saturday, 22nd October, instead of 25th October.
Lec-26 Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon 1

Best Programmers for Lab 7


Section E1 E3 E5 E7 E9 E11 E13 E14 Name Sharun Emanuel Shaju Unnat Jain Anubhav Vardhan Yash Mahanot G V S Sasank Mouli Swapnil Shwetank Jha Anurag Sahay Abhilash Mittal Section E2 E4 E6 E8 E10 E12 E14 E15 Name Harshad Sawhney Rachit Tripathi Sanjay Moudgalya none Gagan Agrawal Shreshth Gandhi Akash Goel Abhinav Mehta

Lec-26

Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon

Recap
Modular programming p g g
divide problem into smaller problems write a separate function for each sub-problem

Lec-26

Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon

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;

We can combine typedef with structure definition:


typedef float float } Point;
Lec-26

struct point { x; y;

Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon

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

char Letters; alpha; int n; Natural;

Lec-26

Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon

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

Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon

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

Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon

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

Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon

10

Linked Lists
Three major operations on linked lists:
Insertion Delete Searching

Lec-26

Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon

11

Any Questions?

Lec-26

Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon

12

Potrebbero piacerti anche