Array in Data Structure_UNIT_I.pdf

Document Details

EnterprisingUnderstanding

Uploaded by EnterprisingUnderstanding

Rajarshi Shahu Mahavidyalaya, Latur

Tags

data structures arrays C++ programming computer science

Full Transcript

Array in Data Structure Prof. Manjusha Anant Shinde Department of Information Technology Rajarshi Shahu Mahavidyalaya (Autonomous) ,Latur { LearnProgramCode } · Ø Ø The elements of array is accessed with reference to its position in array, that is...

Array in Data Structure Prof. Manjusha Anant Shinde Department of Information Technology Rajarshi Shahu Mahavidyalaya (Autonomous) ,Latur { LearnProgramCode } · Ø Ø The elements of array is accessed with reference to its position in array, that is call index or subscript. Like a regular variable, an array must be declared before it is used. A typical declaration for an array in C++ is: type name [elements]; Ø type is a valid type Ø name is a valid Ø elements field int num; Ø BASE TYPE NAME OF ARRAY SIZE OF ARRAY ADVANTAGES OF ARRAY: Arrays can store a large number of value with single name. Ø Arrays are used to process many value easily and quickly. Ø The values stored in an array can be sorted easily. Ø The search process can be applied on arrays easily. TYPES OF ARRAY: Ø ONE DIMENSIONAL ARRAY: A one dimensional array is one in which one subscript /indices specification is needed to specify a particular element of array Declaration : Data_type array_name [size of array ]; Eg: int num; Memory allocation of an array All the data elements of an array are stored at contiguous locations in the main memory. The name of the array represents the base address or the address of the first element in the main memory. Each element of the array is represented by proper indexing. We can define the indexing of an array in the below ways - In the above image, we have shown the memory allocation of an array arr of size 5. The array follows a 0-based indexing approach. The base address of the array is 100 bytes. It is the address of arr. Here, the size of the data type used is 4 bytes; therefore, each element will take 4 bytes in the memory. Basic Terminology Ø Size / Length of Array Ø Index of Array Ø Upper bound and Lower bound of Array Ø int array; a a a a a Size/Length of array = 5 Index of array : 0 to 4 Lower Bound Upper Bound Oprations on Array LDS - This operation is used to print the elements of the array. - It is used to add an element at a particular index. - It is used to delete an element from a particular index. Traversal operation This operation is performed to traverse through the array elements. It prints all array elements one after another. Step 1 : [Initialize Counter] Step 1 : [Initialize Counter] Set K=LB Set i=LB Step 2: Repeat step 3 and step 4 Step 2: Repeat for While K

Use Quizgecko on...
Browser
Browser