An array is a fixed-size container that holds items of the same type, with each item referred to as an element and identified by a numerical index. In C++, arrays can be single-dimensional or multi-dimensional, offering advantages like code optimization and easy data manipulation, but they also have the limitation of fixed size. Basic operations on arrays include traversing, inserting, deleting, searching, and updating elements.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
16 views20 pages
Array Ins Del
An array is a fixed-size container that holds items of the same type, with each item referred to as an element and identified by a numerical index. In C++, arrays can be single-dimensional or multi-dimensional, offering advantages like code optimization and easy data manipulation, but they also have the limitation of fixed size. Basic operations on arrays include traversing, inserting, deleting, searching, and updating elements.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20
Data Structure
Array
Instructure : Elham Rezaie
Date : 2024 What is array • Array is a container which can hold a fix number of items and these items should be of the same type. Most of the data structures make use of arrays to implement their algorithms. Following are the important terms to understand the concept of Array. 1. Element − Each item stored in an array is called an element. 2. Index − Each location of an element in an array has a numerical index, which is used to identify the element. • Array Representation:(Storage structure) Arrays can be declared in various ways in different languages. For illustration, let's take C++ array declaration. Advantages of C++ Array • Code Optimization (less code) • Random Access • Easy to traverse data • Easy to manipulate data • Easy to sort data etc. • Disadvantages of C++ Array • Fixed size C++ Array Types • There are 2 types of arrays in C++ programming: 1. Single Dimensional Array 2. Multidimensional Array Single Dimensional Array Multidimensional Arrays Operations on Array Elements Major Operations • Basic Operations Following are the basic operations supported by an array. 1. Traverse − print all the array elements one by one. 2. Insertion − Adds an element at the given index. 3. Deletion − Deletes an element at the given index. 4. Search − Searches an element using the given index or by the value. 5. Update − Updates an element at the given index Traverse Insertion algorithm • 1. Start • 2. Set J = N • 3. Set N = N+1 • 4. Repeat steps 5 and 6 while J >= K • 5. Set LA[J+1] = LA[J] • 6. Set J = J-1 • 7. Set LA[K] = ITEM • 8. Stop Deletion algorithm • 1. Start • 2. Set J = K • 3. Repeat steps 4 and 5 while J < N • 4. Set LA[J] = LA[J + 1] • 5. Set J = J+1 • 6. Set N = N-1 • 7. Stop