Data Structures in C-session3

Data Structures in C-session3 - Da ta S tructure Linke d...

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

View Full Document Right Arrow Icon
Data Structure Linked List Nima Bari CS103
Background image of page 1

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

View Full DocumentRight Arrow Icon
Dynamic Data Structures Data structures that grow and shrink during execution Linked lists Allow insertions and removals anywhere Stacks Allow insertions and removals only at top of stack Queues Allow insertions at the back and removals from the front Binary trees High-speed searching and sorting of data and efficient elimination of duplicate data items
Background image of page 2
Structures In C What’s a Structure ?
Background image of page 3

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

View Full DocumentRight Arrow Icon
Structures in C It is an entity that is defined as a set of data (fundamental data types, arrays and pointers): As an Example: struct Name { char firstName [50] ; char middleName [50] ; char lastName [100] ; }
Background image of page 4
Self-Referential Structures Self-referential structures Structure that contains a pointer to a structure of the same type Can be linked together to form useful data structures such as lists, queues, stacks and trees Terminated with a NULL pointer/ In ancient days : 0 Diagram of two self-referential structure objects linked together
Background image of page 5

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

View Full DocumentRight Arrow Icon
struct node { int data; struct node *nextPtr; }; nextPtr Points to an object of type node Referred to as a link Ties one node to another node
Background image of page 6
Memory Allocation for Structures Set aside real memory to create structure malloc is a predefined library function for performing dynamic memory allocation in the C malloc is part of the standard library and is declared in the stdlib.h
Background image of page 7

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

View Full DocumentRight Arrow Icon
Example : int *p = (int *) malloc(10, sizeof(int)); Allocates 10 integers equiv to int p[10]; char *s = (char *) malloc(25, sizeof(char)); char s[25] ; node *myNode = (node *) malloc(1, sizeof(node)); Creates 1 node struct in memory
Background image of page 8
Linked Lists Linked list Connected by pointer links
Background image of page 9

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

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

Page1 / 27

Data Structures in C-session3 - Da ta S tructure Linke d...

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

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