Array Insertion At Any PositionCode CrazeMar 5, 20231 min read#include <stdio.h>void main() { int a[100],i; int eb,size,pos; printf("\nEnter the size of array : "); scanf("%d",&size); for(i=0;i<size;i++) { printf("\nEnter element : "); scanf("%d",&a[i]); } printf("\n----Array----\n"); for(i=0;i<size;i++) { printf(" %d",a[i]); } printf("\nEnter element : "); scanf("%d",&eb); printf("\nEnter the position : "); scanf("%d",&pos); for(i=size-1;i>=pos-1;i--) { a[i+1]=a[i]; } a[pos-1]=eb; size++; printf("\n----Latest Array----\n"); for(i=0;i<size;i++) { printf(" %d",a[i]); } }
#include <stdio.h>void main() { int a[100],i; int eb,size,pos; printf("\nEnter the size of array : "); scanf("%d",&size); for(i=0;i<size;i++) { printf("\nEnter element : "); scanf("%d",&a[i]); } printf("\n----Array----\n"); for(i=0;i<size;i++) { printf(" %d",a[i]); } printf("\nEnter element : "); scanf("%d",&eb); printf("\nEnter the position : "); scanf("%d",&pos); for(i=size-1;i>=pos-1;i--) { a[i+1]=a[i]; } a[pos-1]=eb; size++; printf("\n----Latest Array----\n"); for(i=0;i<size;i++) { printf(" %d",a[i]); } }
Stack Using QueueA stack can be implemented using two queues in C. The basic idea is to use one queue for enqueue operations and another for dequeue...
Comments