Welcome to CseNotes12.in

CseNotes12 official Website help for Computer Science Student. This is a Website about Providing Engineering Notes,PPTs ,Question Papers,Codes ,Projects, Hand Written Notes ,Books ,PDF,MCQs Questions,It is strictly According to the syllabus of Lovely Professional University .It is for all students who are studying B.Tech and for others also college students .Computer Science Notes are available here on this site.Csenotes12 .This is Best Computer Science Website :) .


PEP DATA STRUCTURE PRACTICE



DATA STRUCTURE PEP PRACTICE : 


Data Structure is a way to store and organize data so that it can be used efficiently . For example, we can store a list of items using array,linked list,stack,queue,tree,graph.


1. Array : In this topic we will learn   = >


  • --->Array Insertion  
  • --->Array Deletion
  • --->Array Rotation

                                                                       Array Insertion  

#include<iostream>
using namespace std;
int main()
{
int a[50],size,num,pos;
cin>>size;
if(size>50)
{
cout<<"overflow!!"<<endl;
}else
{
for(int i=0;i<size;i++)
{
cin>>a[i];
}
cin>>num>>pos;
for(int i=size-1;i>=pos-1;i--)
{
a[i+1]=a[i];
}
a[pos-1]=num;
size++;
for(int i=0;i<size;i++)
{
cout<<a[i]<<" ";
}
}
}
-----------------------------------------Complexity(worst case) : O(n) ------------------------------------------------------


                                                              Array Deletion


#include<iostream>
using namespace std;
int main()
{
int a[50],size;
cin>>size;
for(int i=0;i<size;i++)
{
cin>>a[i];
}
int pos;
cin>>pos;
if(pos<=0||pos>size)
{
cout<<"invalid condition !"<<endl;
}else
{
for(int i=pos-1;i<size-1;i++)
{
a[i]=a[i+1];
}
size--;
for(int i=0;i<size;i++)
{
cout<<a[i]<<" ";
}
}

}


-----------------------------------------Complexity(worst case) : O(n) ------------------------------------------------------




                                                        Array Rotation
EX : 


Before Rotation-------------------=>  1 , 2 , 3 , 4 , 5 , 6
After Rotation----------------------=>  3 , 4 , 5 , 6 , 1 , 2


#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int d;
cin>>d;
int b[n];
for(int i=0;i<n;i++)
{
b[(i+d)%n]=a[i];
}
for(int i=0;i<n;i++)
{
cout<<b[i]<<" ";
}
}