0% found this document useful (0 votes)
22 views4 pages

Ads Lab Assessment 1

Uploaded by

jayasimman851
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views4 pages

Ads Lab Assessment 1

Uploaded by

jayasimman851
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ADS LAB ASSESSMENT 1

Q 1)

AIM:

To print the elements of an array after left rotating array elements by d


positions.

SOURCE CODE:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void leftRotate(vector<int>& arr, int d){


reverse(arr.begin(),arr.begin() + d);
reverse(arr.begin() + d, arr.end());
reverse(arr.begin(), arr.end());
}

int main(){

int n, d;
cin >> n >> d;
vector<int> arr(n);

for(int i = 0; i < n; ++i)


cin >> arr[i];

leftRotate(arr, d);
cout << "Array after rotating is : \n";
for(auto i: arr)
cout << i << " ";

cout << "\n";

return 0;
}

OUTPUT:

RESULT:

Thus the given program is verified.

Q 2)

AIM:

To print all the Repeated Numbers with their frequency in an array .


SORCE CODE:

#include <iostream>
#include <unordered_map>
using namespace std;
int main()
{
int len= 10;
int arr[len]= {2,5,3,2,4,5,3,6,7,3};
unordered_map<int, int> mymap;
for(int i= 0; i<len; i++){
mymap[arr[i]]+= 1;
}
cout<<"Repeating nos: "<<endl;
for(auto itr= mymap.begin(); itr!= mymap.end(); itr++){
if(itr->second>1){
cout<<itr->first<<"\t"<<itr->second<<endl;
}
}
cout<<endl<<"Non repeating nos: "<<endl;
for(auto itr= mymap.begin(); itr!= mymap.end(); itr++){
if(itr->second==1){
cout<<itr->first<<" ";
}
}
return 0;
}

OUTPUT:
RESULT :

Thus the repeated numbers in a array are printed.

You might also like