Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary data structures

Rating
-
Sold
-
Pages
2
Uploaded on
17-05-2023
Written in
2022/2023

providing an in-depth , complete and well written description.

Institution
Course

Content preview

1.3 Array Operations | Deletion from Array |
Explanation with Code | Data Structure


In this video, we will discuss the deletion operation in arrays. We
will use an example array of size 5 to explain the process of
deleting data from a specific position, beginning, and end of the
array. We will also write the code and analyze the time
complexity of the operation.

First, we initialize an array of size 50 but ask the user for the
number of elements they want to insert. We then populate the
array with the user's input and ask them which position they want
to delete data from. For example, if they choose position 2 (index
1), we cannot leave that space blank. Instead, we shift the
elements to fill the empty space and decrease the size of the
array by 1.

We start a loop to shift the elements to the left, starting from the
index before the position chosen by the user until the second last
index of the array. We shift the element at index i+1 to index i
and continue until the end of the loop, overwriting the deleted
element. If we want to print the deleted data, we store it in a
separate variable before shifting the elements.

We provide the code for the deletion operation, where we ask the
user for the position to delete, check if it's a valid position, and
then start the loop to shift the elements.

int size = 5; int arr[size]; int pos, i; int
item; // ask user for position to delete
printf("Enter position to delete: "); scanf("%d",
&pos); // check if valid position if (pos <= 0 ||
pos > size) { printf("Invalid position"); } else
if (pos == size) { printf("No data at position %d",
pos); } else { // start loop to shift elements

Written for

Institution
Course

Document information

Uploaded on
May 17, 2023
Number of pages
2
Written in
2022/2023
Type
SUMMARY

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
pavan1

Get to know the seller

Seller avatar
pavan1 RVR&JCCE
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
2
Last sold
-
data structures and algorithms

simple understanding

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions