Self Referential Structure. A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };

Slides:



Advertisements
Similar presentations
Linked Lists Mohammed Almashat CS /03/2006.
Advertisements

CHP-5 LinkedList.
1 Structures. 2 User-Defined Types C provides facilities to define one’s own types. These may be a composite of basic types ( int, double, etc) and other.
Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
M180: Data Structures & Algorithms in Java
Advanced Data Structures Stack –a stack is dynamic data items in a linear order, such that the item first "pushed" in is the last item "popped" out. Think.
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Computer Programming Link List (Insertion, Printing and Deletion functions) Lecture 23.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures.
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are crated using the class definition. Programming techniques.
©Brooks/Cole, 2003 Chapter 11 Data Structures. ©Brooks/Cole, 2003 Data Structure Data structure uses collection of related variables that can be accessed.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
 2006 Pearson Education, Inc. All rights reserved Data Structures.
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
Chapter 8: Data Abstractions Senem Kumova Metin. 8-2 Chapter 8: Data Abstractions 8.1 Basic Data Structures – Arrays – Lists, Stacks, Queues – Trees 8.2.
ECE 103 Engineering Programming Chapter 61 Abstract Data Types Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.
Applications of Data-Structure
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
Lists, Stacks and Queues in C Yang Zhengwei CSCI2100B Data Structures Tutorial 4.
Self-Referential Classes A Self-referential class is a class that contains a reference to an object that has the same class type. –A self-referential class.
1 Chapter 17 – Data Structures Outline Introduction Self-Referential Classes Dynamic Memory Allocation Linked Lists Stacks Queues Trees.
Lists Chapter 8. 2 Linked Lists As an ADT, a list is –finite sequence (possibly empty) of elements Operations commonly include: ConstructionAllocate &
Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the.
Kovács Zita 2014/2015. II. félév DATA STRUCTURES AND ALGORITHMS 26 February 2015, Linked list.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Chapter 16 – Data Structures and Recursion. Data Structures u Built-in –Array –struct u User developed –linked list –stack –queue –tree Lesson 16.1.
Subject Name : Data Structure Using C Title : Linked Lists
Review 1 Polish Notation Prefix Infix Postfix Precedence of Operators Converting Infix to Postfix Evaluating Postfix.
Linked Lists. Introduction In linked list each item is embedded in a link Each item has two parts – Data – Pointer to the next item in the list Insert,
Revision on C++ Pointers TCP1201: 2013/2014. Pointer Basics  Why pointer is important? 1. Reference/Point to existing data without cloning the data.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Linked Lists Linked Lists Dale.
Department of Computer Science 1 Some Practice Let’s practice for the final a little bit. OK?
 Array is a data structure were elements are stored in consecutive memory location.in the array once the memory is allocated.it cannot be extend any more.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
ENEE150 – 0102 ANDREW GOFFIN Dynamic Memory. Dynamic vs Static Allocation Dynamic  On the heap  Amount of memory chosen at runtime  Can change allocated.
Linked list: a list of items (nodes), in which the order of the nodes is determined by the address, called the link, stored in each node C++ Programming:
Linked List. LINKED LIST Link is collection of similar type of elements. There are two ways of maintaining a list in memory. The first way is store the.
C Structs Programming in C++ Fall 2008 Dr. David A. Gaitros
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Linked Lists Outline Introduction Self-Referential Structures.
Linked Lists Chapter Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.
Sections Basic Data Structures. 1.5 Data Structures The way you view and structure the data that your programs manipulate greatly influences your.
  A linked list is a collection of components called nodes  Every node (except the last one) contains the address of the next node  The address of.
Data Structure and Algorithm: CIT231 Lecture 6: Linked Lists DeSiaMorewww.desiamore.com/ifm1.
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
STACKS & QUEUES for CLASS XII ( C++).
Data Structure By Amee Trivedi.
Chapter 12 – Data Structures
5.13 Recursion Recursive functions Functions that call themselves
CSCI-255 LinkedList.
UNIT – I Linked Lists.
Linked Lists Chapter 6 Section 6.4 – 6.6
12 C Data Structures.
UNIT-3 LINKED LIST.
Linked lists.
Tree data structure.
Pointers and Linked Lists
Tree data structure.
Review & Lab assignments
Indirection.
Dynamic Data Structures
KENDRIYA VIDYALAYA SANGATHAN (AGRA REGION)
Chapter 17: Linked Lists.
CS148 Introduction to Programming II
Linked lists.
Arrays and Pointers.
Dynamic Data Structures
Presentation transcript:

Self Referential Structure

A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };

Self Referential Structure However, a structure may contain a pointer of same type. They allow you to create data structures that contains references to data of the same type as themselves. This type of structure, called self referential structure struct check { int a; struct check *p; // Valid };

Self Referential Structure Self-referential Structure is used in data structure such as linked list, Binary tree, stack, Queue etc.

Self Referential Structure Linked List Method of organizing stored data in a computedata Collection of Nodes Each Nodes contains 2 parts Information Part and Link Part Information Part contains actual data Link part(address Part) contains address of next Node Linked-Lists are useful because, can insert or delete Nodes very easily. Unlike arrays, there are no issues of reallocating memory and copying data. It is Dynamic Memory allocation( Run time) Data Address

Self Referential Structure Linked List The last node address will be ‘Null’ By Interchanging of links(Address) part, can easily insert or delete a node at run time Eg: Inserting a node Data Address Data Address Data NULL

Self Referential Structure Example to creating Linked List struct list { int data; struct list *link; }; struct list node; Node  variable of type struct list, contains node.data (actual data) and node.link (address of next node of same type)