answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<conio.h>

void main()

{

int a[10],i,j,k,n;

printf("enter number of elements of array");

scanf("%d",n);

printf("Enter array elements");

for(i=1;i<=n;i++)

{

scanf("%d",a[i]);

}

printf("enter the element you want to delete");

scanf("%d",k);

for(j=0;j<n;j++)

{

if(a[j]==k)

{

a[j]=a[j+1];

n=n-1;

}

}

printf("The array after deletion of %d is:",k);

for(i=1;i<n;i++)

{

printf("%d",a[i]);

}

getch();

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

A queue is a FIFO data storage structure, where FIFO stands for first-in, first-out. A simple queue supports two basic operations: fetch the element at the front of the queue (if any), and insert an element at the end of the queue (if space is available).

A simple implementation of a finite-size queue using the hypothetical data type QType could be implemented using a simple ring buffer like so:

#define Q_SIZE 5

static struct {

int head;

int tail;

QType data[Q_SIZE];

} q = { 0, 0 };

bool get_first(QType* const result) {

bool ok = false;

if (result && q.head != q.tail) {

*result = q.data[q.head];

q.head = ++q.head % Q_SIZE;

ok = true;

}

return ok;

} // first

bool add_last(QType me) {

bool ok = false;

int next = q.tail++ % Q_SIZE;

if (next != q.head) {

q.data[q.tail] = me;

q.tail = next;

ok = true;

}

return ok;

} // add

A straight-forward implementation with an array and a constant head position at index zero is inferior, as every removal of the head element requires moving all other queued elements forward by one index. The implementation based on a ring buffer avoids this step.

More complex queues support deletion (removal of an element which is not at the head of the queue), for example when a maximum waiting time expired or other circumstances change, and the insertion of new elements with different priority levels (higher priority elements can push ahead of lower priority ones).

Most queue implementations will also support predicates to query the number of elements currently queued up (without changing the queue), and many allow to peek into the queue (obtain an element without removing it from the queue).

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

#include<iostream>

#include<vector>

#include<cassert>

int main()

{

std::vector<int> a = {0, 1, 2, 3, 4};

assert (a.size() 5);

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program in c plus plus in which insertion and deletion in an array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a program that accepts 50 integer values and sort them in basic programming?

Create an array with 50 elements and input the integers one a time, filling the array. Use an insertion sort on the array for each input except the first. Alternatively, input the values first and then use insertion sort.


Why you used link list in binary tree?

Linked list was introduced to reduce the space wastage done by array &amp; also to make easier the insertion and deletion of elements from a list. A binary tree contains nodes of elements where insertion,deletion &amp; searching is frequently done. So to make these operations easier linked list is used.


Which linked list can be randomly accessed by given locations?

In a word, none. Linked lists are sequential and must be traversed sequentially. For random access you need an array, but you lose the efficiency of a list when it comes to insertion/deletion.


What are the various operations that can be performed on a queue?

In queue insertion takes place on rear end and deletion takes place on front end. INSERTION(QUEUE,N,FRONT,REAR,ITEM) :QUEUE is the name of a array on which we are implementing the queue having size N. view comlete ans at http://mcabcanotes.in/algorithm-to-perform-insertion-and-deletion-in-a-queue/


How do you write a C Program to fill up an Integer Array?

Reference:cprogramming-bd.com/c_page1.aspx# array programming


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


Could you Write a program for 8086 microprocessor that displays on the monitor the average of 2 numbers from an array?

How to write a program for mouse in microprocessor?


What are limitations of array?

1) Array is a static data structure. Hence it has to be declared with a fixed size. Changing the size of the array involves procedures like relocation, freeing memory space, etc2) They hold elements of the same data type. Hence they are not suitable for storing and working with different data types. 3) Insertion and deletion in any place other than the end of the array has a time complexity of O(n).


How do you write an assembly language program to find the sum of n numbers using array?

write an assembly language program to find sum of N numbers


How do you write a program in C to find and display the sum of each row and column of a 2 dimensional array of type float?

array type


Write a c program to find the maximum value of 25 element in an array?

int findMax(int *array) { int max = array[0]; for(int i = 1; i &lt; array.length(); i++) { if(array[i] &gt; max) max = array[i] } return max; }


Write Algorithm to perform the insertion and deletion operation of a linear array?

//Algorithm to perform the insertion and deletion operation of a linear arrayINSERT (ArrA, n, i, item) where ArrA is a linear array with n elements and i is a positive integer where i &lt;=n. The element 'item' will be inserted into the ith position in ArrA.1. j = n2. repeat steps 3 and 4 while j &gt;= i3. ArrA[j+1] = ArrA[j]4. j = j - 15. ArrA[i] = item6. n = n+1DELETE (ArrA, n, i, item) where ArrA is a linear array with n elements and i is a positive integer where i &lt;=n. The element 'item' will be deleted from the ith position in ArrA.1. item = ArrA[i]2. repeat for j = i to n -1 ArrA[j] = ArrA[j+1]4. n = n - 1NO HARD RETURNS ALLOWED