0% found this document useful (0 votes)
111 views

Array Abstract Data Type in C - Dot Net Tutorials

This document discusses arrays as an abstract data type (ADT) in C and C++. It defines an ADT as having two parts: 1) a representation of data and 2) a set of operations on that data. For arrays, the representation is defined by the language compiler, while common operations include accessing, inserting, deleting, searching and reversing elements. These operations are demonstrated using a C program that initializes an integer array, takes user input to populate it, and allocates the array in either stack or heap memory.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views

Array Abstract Data Type in C - Dot Net Tutorials

This document discusses arrays as an abstract data type (ADT) in C and C++. It defines an ADT as having two parts: 1) a representation of data and 2) a set of operations on that data. For arrays, the representation is defined by the language compiler, while common operations include accessing, inserting, deleting, searching and reversing elements. These operations are demonstrated using a C program that initializes an integer array, takes user input to populate it, and allocates the array in either stack or heap memory.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

DSA – Introduction

Array Abstract Data Type


 Introduction to Data
Structure
Back to: Data Structures and Algorithms Tutorials
 Physical vs Logical Data
Structure
 Stack vs Heap Memory Array as ADT (Abstract Data Type) using C and C++ Language:
 Abstract Data Type (ADT)
 Time and Space In this article, I am going to discuss  Array as ADT (Abstract Data Type) using C and C++ Language with
Complexity Examples. What do we mean by ADT here? ADT means –

 What is Algorithm
1. Representation of Data.
 Analysis of Algorithm
2. Set of Operations on the Data.
 Big-O Notation
 Properties of Asymptotic C/C++ provides Array as a basic data structure. Representation of data is defined by the language compiler itself.
Notations But the operations on the data are not defined by the compiler. We have to implement or provide the operations on
Array data structure. So, data structure array and the set of operations together we can call it as Abstract Data
 Master Theorem
Type (ADT).
 Recursion And
BackTracking
Operations on Array Data Structure:
Essential Concepts of C and
C++ Programming Below is the list of some of the operations that we can perform on an array-

 Arrays
 Structure
 Pointers
 References in C++
 Pointer to Structure
 Functions
 Parameter Passing
Methods
 Array as Parameter
 Structure as Parameter
 Structures and Functions
 Converting a C Program
to C++
 Class and Constructor in
C++
We can perform more operations on the array data structure but the above are some basic operations. Let us
 Template Classes in C++
give some information about the above functions-
Environment Setup for
Programming 1. Display () – To Display the entire array on the screen.
2. Add(n) / Append(n) – To add a particular element on the end of the array.
 Setup Dev C++ and
3. Insert (index, n) – To add an element to a particular index.
Settings
4. Delete (index) – To delete an element with the help of an index in the given array.
 Code Blocks IDE Setup 5. Search (n) – To check whether the given element is present or not in an array.
and Settings
6. Get (index) – It will return the element which presents on the given index.
7. Set (index, x) – It will change the element with the new element at a particular index.
Recursion
8. Max () / Min () – These will return the max and min element in the given array.
 How does Recursion 9. Reverse () – It will reverse the order of elements in the given array.
works in C and C++? 10. Shift () – It will shift the whole elements either on the left or right side by the given number.
 How Recursion Uses Stack
 Time Complexity of Representation of Data on Array:
Recursive Function
Now let’s look at the representation of the data on an array.
 Static and Global
Variables in Recursion
 Tail Recursion
 Head Recursion
 Tree Recursion
 Indirect Recursion 
 Nested Recursion
 Sum of First N Natural
Number in C
 Factorial of a Number in C The first thing is we need an array space of some size. Here we initialize an array of size = 10 and length = 0
 Power of a number Using because there are no elements in the array.
Recursion in C
 Taylor Series Using
Recursion in C
 Taylor Series Using
Horner’s Rule
 Combination Formula
using Recursion in C
 Fibonacci Series using
Recursion in C
Here we have two methods to initialize our Array:
 Tower Of Hanoi using
Recursion in C 1. Inside Stack Memory: As shown in the below image, A [10] will create a contiguous block of memory
index from 0 to 9 inside Stack.
Array – Representation
2. Inside Heap Memory: We can also create our array dynamically with the new keyword, The new
 Array Declaration and operator denotes a request for memory allocation, as shown in the below image, we created a
Initialization pointer of int* type and in the next step we point it to a contiguous block of memory inside Heap. We
 Static vs Dynamic Array in have created our array inside heap memory by using a pointer.
C/C++
 How to increase the size
of an Array
 2-D Arrays in C/C++
 Array Representation by
Compiler

Array – ADT The Complete C Code:


 Array Abstract Data
#include <stdio.h>
Type
#include <stdlib.h>
 Display Append and
Insert Elements in an struct Array {
Array int* A;
int size;
 How to Delete an
int length;
Element at a Particular };
Index in a given Array
 Linear Search in Array  int main() {
struct Array arr;
 Binary Search in C
 Array Basic Operations in printf("Enter Size of an Array: ");
C scanf("%d", &arr.size);
 Array Reverse and Shift
arr.A = (int*)malloc(sizeof(int) * arr.size);
Operations in C
arr.length = 0;
 Checking if Array is Sorted
in C printf("Enter Number of Elements: ");
 Merging Arrays in C scanf("%d", &arr.length);

 Array Set Operations in C


printf("Enter All Elements: \n");
 Menu Driven Program for (int i = 0; i < arr.length; i++) {
using Array in C scanf("%d", &arr.A[i]);
 How to Convert Array C }
Code to C++ Code
getchar();
 Finding Single Missing }
Element in an Array in C
 Finding Multiple Missing Output:
Elements in an Array in C

You might also like