Array using List

 Implementation of list using array



***  Here  is the code ***



#include<bits/stdc++.h>

#include<stdio.h>

#define SIZE 6

using namespace std;

int main()

{

int array[SIZE],index,item,i;

cout<<"Enter the elements in array\n";

for(int i=0; i<SIZE-1; ++i)

{

scanf("%d",&array[i]);

}

for(int i=0; i<SIZE; ++i){

cout<<array[i]<<"\t";

}

cout<<"\n";

// for(int i=6-1; i>=n; --i)

// arra[i] = arra[i];

// arra[i+1]=item;

//

// for(int i=0; i<6; ++i){

// cout<<arra[i]<<"\t";

// }


    cout<<"Enter the index you want to enter item"<<"\n";

    cin>>index;

    cout<<"Enter the item to put"<<"\n";

    cin>>item;

    // we track item from back to left.....

    for(i = SIZE-2; i>=index; --i)

        array[i+1] = array[i];

    array[i+1] = item;

cout<<"\n"<<"******************************"<<"\n";

for(i=0; i<SIZE; ++i){

cout<<array[i]<<"\t";

}

return 0;

}

Comments

Popular posts from this blog

About RAM

Class and object in c++