Array in data structure

Google Advertisements

Prev Tutorial Next Tutorial

Array in Data Structure in C++

An Array is a collection of similar data type value in a single variable. An array is a derived data type in C, which is constructed from fundamental data type of C language.

array

Insert Element in Array at Specific Position in C++

Insert Element in Array in C++

	
#include<iostream.h>
#include<conio.h>

void main()
  {
  int i,a[5],no,pos;
  clrscr();
  cout<<"Enter element in array: ";
  for(i=0;i<5;i++)
  {
  cin>>a[i];
  }
  cout<<"\nStored element in array: ";
  for(i=0;i<5;i++)
  {
  cout<<a[i];
  }
  cout<<"\nEnter position for enter element: ";
  cin>>pos;
  if(pos>5)
  {
  cout<<"\nThis is out of range";
  }
  else
  {
  cout<<"\nEnter new element: ";
  cin>>no;
  --pos;
  for(i=5;i>=pos;i--)
  {
  a[i+1]=a[i];
  }
  a[pos]=no;
  cout<<"\nStored data in array: ";
  for(i=0;i<6;i++)
  {
  cout<<a[i];
  }
  }
  getch();
  }

Output

	
Enter elements in array: 5
4
6
7
2
8
Stored data in array: 2 4 6 7 8
Enter position for enter element: 3
Enter new element: 11
Stored data in array: 4 2 5 7 8

Sort Array Elements in C++

Sort Array Element in C++

#include<iostream.h>
#include<conio.h>

void main()
{
int i,a[10],temp,j;
clrscr();
cout<<"Enter any 10 num in array: \n";
for(i=0;i<=10;i++)
{
cin>>a[i];
}
cout<<"\nData before sorting: ";
for(j=0;j<10;j++)
{
cout<<a[j];
}
for(i=0;i<=10;i++)
{
for(j=0;j<=10-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"\nData after sorting: ";
for(j=0;j<10;j++)
{
cout<<a[j];
}
getch();
}

Output

	
Enter any 10 num in array:
10
50
30
20
60
80
70
90
100
Data before sorting: 10 50 30 20 60 80 70 90 100
Data after sorting: 10 20 30 40 50 60 70 80 90 100

Delete Array Element at Specific Position in C++

Delete element from Array in C++

	
#include<stdio.h>
#include<conio.h>

void main()
 {
 int i,a[5],no,pos;
 clrscr();
 cout<<"Enter element in array: ";
 for(i=0;i<5;i++)
 {
 cin>>a[i];
 }
 cout<<"\nStored element in array: ";
 for(i=0;i<5;i++)
 {
 cout<<a[i];
 }
 cout<<"\nEnter poss. of element to delete: ";
 cin>>pos;
 if(pos>5)
 {
 cout<<"\nThis value is out of range ";
 }
 else
 {
 --pos;
 for(i=pos;i<=4;i++)
 {
 a[i]=a[i+1];
 }
 cout<<"\nAfter deletion elements in array: ";
 for(i=0;i<4;i++)
 {
 cout<<a[i];
 }
 }
 getch();
 }
 

Output

	
Enter element in array: 10 30 50 20
Stored element in array: 10 30 50 20
Enter poss. of element to delete: 3
After deletion elements in array: 10 30 20

Prev Tutorial Next Tutorial

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. If you want to post your article on our website/FB Group/FB Page please contact on [email protected] or 8076671483

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: [email protected] or 8076671483

Path variable is set for providing path for all Java tools like java, javac, javap, javah, jar, appletviewer which are used in java programming. All these tools are available in bin folders so we set path upto bin folders.

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar.

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user.

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects.

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: [email protected] or 8076671483 Try this Keyword C++ Programs