Data Structure Tutorial PDF

Summary

This tutorial provides an overview of data structures in C++. It details the definition, importance, classification and examples for using data structures. The tutorial also covers how to create, initialize and access structure members in C++.

Full Transcript

Data Structure Introduction Created by : Eng/Amira Eng/Ahmed Eng/Dina Lotfy Hatem Elkholy Expectations??? Agnda 0 1 Introduction To 02 Structures Data Structure Definition of data Definition of structures structure...

Data Structure Introduction Created by : Eng/Amira Eng/Ahmed Eng/Dina Lotfy Hatem Elkholy Expectations??? Agnda 0 1 Introduction To 02 Structures Data Structure Definition of data Definition of structures structure and why to use. Difference between Important of data Array and Structure. structure in Struct Declaration and program members initialization. Access Structure Classification of Members. data structure 01 Introduction To Data Structure Definition of data structure A data structure is a storage that is used to store and organize data. It is a way of arranging data on a computer so that it can be accessed and updated efficiently Important of data structure in program Optimizes Resource Utilization Well-designed data structures ensure that data is stored and accessed in the most optimized way, reducing memory usage and improving overall performance. Improves Code Efficiency Data structures impact the efficiency of code. By choosing the appropriate data structure for a specific problem, developers can reduce the time and computational resources required for operations such as searching, sorting, and inserting data. Facilitates Scalability and Flexibility By using scalable data structures, developers can accommodate larger datasets and handle increased user loads without sacrificing performance. Important of data structure in program cont. … Program To Run Program Data Storage CPU Memory Instructions Data Data Code Code HDD RAM Or SSD Classification of data structure Data Structure Linear Data Non-linear Data Structure Structure Static Data Dynamic Data Tree Graph Structure Structure Linked Array Queue Stack list 02 Structure What is a Structure? Why? Member variables weight price Structure What is a Structure ? Cont… Structures (also called structs) are a way to group several related variables into one place. Each variable in the structure is known as a member of the structure. Structures in C++ can contain two types of members: 1. Data Member: These members are normal C++ variables. 2. Member Functions: These members are normal C++ functions, we can include functions inside a structure declaration. Difference between Array and Structure Unlike an array, a structure can contain many different data types (int, string, bool, etc.). Array uses subscripts or '[ ]' (square brackets) to access the elements but Structure uses the '.' (dot operator) to access the elements. Struct Declaration Struct Declaration:- struct structure_name { // members declaration. }; (Example) struct NewStructure { // Structure declaration int myNum; // Member (int variable) string myString; // Member (string variable) }; How to Create Structure Variable? A structure variable can either be declared with structure declaration or as a separate declaration like basic types. Important Note // A variableWhen the structure declaration is data like basic declared, // A no variable declaration with memory types(separate is allocated. declaration ) When structure the variable of declaration. (Example) a structure is created, then the memory is (Example) allocated. struct NewStructure { struct NewStructure { int myNum; int myNum; string myString; string myString; }; }MyStructVariable; // Structure int main() variable {NewStructure s; } // Structure variable How to initialize structure members? Structure members can be initialized Structure members can be initialized with declaration in C++. using curly braces ‘{}’. How to access structure elements? Structure members are accessed using the dot (.) operator. C++ Struct Example: Using Constructor and Method Thank You

Use Quizgecko on...
Browser
Browser