dataid field USA_trkdpit_IntFV_matrix AACR USA_trkdpit_IntFV_matrix…

dataid field
USA_trkdpit_IntFV_matrix AACR
USA_trkdpit_IntFV_matrix AARG
USA_trkdpit_IntFV_matrix ACAE
USA_trkdpit_IntFV_matrix ADEP
USA_trkdpit_IntFV_matrix AGWI
USA_trkdpit_IntFV_matrix AINT
USA_trkdpit_IntFV_matrix AITL
USA_trkdpit_IntFV_matrix AOAS
USA_trkdpit_IntFV_matrix APDA
USA_trkdpit_IntFV_matrix APPN
USA_trkdpit_IntFV_matrix APPY
USA_trkdpit_IntFV_matrix APTC
USA_trkdpit_IntFV_matrix ATCA
USA_trkdpit_IntFV_matrix ATOT
USA_trkdpit_IntFV_matrix ATRC
USA_trkdpit_IntFV_matrix CIAC
USA_trkdpit_IntFV_matrix ECOR
USA_trkdpit_IntFV_matrix EIBT
USA_trkdpit_IntFV_matrix ESGA
USA_trkdpit_IntFV_matrix ETOE
USA_trkdpit_IntFV_matrix FCDP
USA_trkdpit_IntFV_matrix FCSN
USA_trkdpit_IntFV_matrix FFCF
USA_trkdpit_IntFV_matrix FLDN
USA_trkdpit_IntFV_matrix FLDR
USA_trkdpit_IntFV_matrix FPRD
USA_trkdpit_IntFV_matrix FPSS
USA_trkdpit_IntFV_matrix FTLF
USA_trkdpit_IntFV_matrix ICEX
USA_trkdpit_IntFV_matrix IICF
USA_trkdpit_IntFV_matrix ITLI
USA_trkdpit_IntFV_matrix LAEX
USA_trkdpit_IntFV_matrix LAPB
USA_trkdpit_IntFV_matrix LBDT
USA_trkdpit_IntFV_matrix LLTD
USA_trkdpit_IntFV_matrix LLTL
USA_trkdpit_IntFV_matrix LTCL
USA_trkdpit_IntFV_matrix LTLL
USA_trkdpit_IntFV_matrix LTTD
USA_trkdpit_IntFV_matrix NIBX
USA_trkdpit_IntFV_matrix NIEN
USA_trkdpit_IntFV_matrix NINC
USA_trkdpit_IntFV_matrix OACR
USA_trkdpit_IntFV_matrix OAPB
USA_trkdpit_IntFV_matrix OBDT
USA_trkdpit_IntFV_matrix OITL
USA_trkdpit_IntFV_matrix ONCI
USA_trkdpit_IntFV_matrix ONET
USA_trkdpit_IntFV_matrix OOAS
USA_trkdpit_IntFV_matrix OOLB
USA_trkdpit_IntFV_matrix OTLO
USA_trkdpit_IntFV_matrix OUIE
USA_trkdpit_IntFV_matrix QCMS
USA_trkdpit_IntFV_matrix QCOM
USA_trkdpit_IntFV_matrix QCSO1
USA_trkdpit_IntFV_matrix QPIC
USA_trkdpit_IntFV_matrix QRED
USA_trkdpit_IntFV_matrix QTCO
USA_trkdpit_IntFV_matrix QTEL
USA_trkdpit_IntFV_matrix QTLE
USA_trkdpit_IntFV_matrix QTLL
USA_trkdpit_IntFV_matrix RNTS
USA_trkdpit_IntFV_matrix RTLR
USA_trkdpit_IntFV_matrix SBAI
USA_trkdpit_IntFV_matrix SBAS
USA_trkdpit_IntFV_matrix SBBF
USA_trkdpit_IntFV_matrix SBDA
USA_trkdpit_IntFV_matrix SBDT
USA_trkdpit_IntFV_matrix SBIT
USA_trkdpit_IntFV_matrix SCEX
USA_trkdpit_IntFV_matrix SCIP
USA_trkdpit_IntFV_matrix SCMS
USA_trkdpit_IntFV_matrix SCOR
USA_trkdpit_IntFV_matrix SCSI
USA_trkdpit_IntFV_matrix SCTP
USA_trkdpit_IntFV_matrix SCUI
USA_trkdpit_IntFV_matrix SCUR
USA_trkdpit_IntFV_matrix SDAI
USA_trkdpit_IntFV_matrix SDBF
USA_trkdpit_IntFV_matrix SDED
USA_trkdpit_IntFV_matrix SDEP
USA_trkdpit_IntFV_matrix SDNI
USA_trkdpit_IntFV_matrix SDWS
USA_trkdpit_IntFV_matrix SETR
USA_trkdpit_IntFV_matrix SFCF
USA_trkdpit_IntFV_matrix SGPP
USA_trkdpit_IntFV_matrix SGRP
USA_trkdpit_IntFV_matrix SICF
USA_trkdpit_IntFV_matrix SIEN
USA_trkdpit_IntFV_matrix SIIN
USA_trkdpit_IntFV_matrix SLTL
USA_trkdpit_IntFV_matrix SNCB
USA_trkdpit_IntFV_matrix SNCC
USA_trkdpit_IntFV_matrix SNCE
USA_trkdpit_IntFV_matrix SNCI
USA_trkdpit_IntFV_matrix SNIN
USA_trkdpit_IntFV_matrix SNPM
USA_trkdpit_IntFV_matrix SNTD
USA_trkdpit_IntFV_matrix SOCA
USA_trkdpit_IntFV_matrix SOCF
USA_trkdpit_IntFV_matrix SOCL
USA_trkdpit_IntFV_matrix SOL1
USA_trkdpit_IntFV_matrix SOL23
USA_trkdpit_IntFV_matrix SOL2
USA_trkdpit_IntFV_matrix SOL3
USA_trkdpit_IntFV_matrix SOL45
USA_trkdpit_IntFV_matrix SOL4
USA_trkdpit_IntFV_matrix SOLA
USA_trkdpit_IntFV_matrix SOPI
USA_trkdpit_IntFV_matrix SOPP
USA_trkdpit_IntFV_matrix SOTE
USA_trkdpit_IntFV_matrix SPTM
USA_trkdpit_IntFV_matrix SQCK
USA_trkdpit_IntFV_matrix SREV
USA_trkdpit_IntFV_matrix SSGA
USA_trkdpit_IntFV_matrix STBP
USA_trkdpit_IntFV_matrix STBV
USA_trkdpit_IntFV_matrix STEC
USA_trkdpit_IntFV_matrix STLD
USA_trkdpit_IntFV_matrix STSI
USA_trkdpit_IntFV_matrix TIAT
USA_trkdpit_IntFV_matrix TTAX
USA_trkdpit_IntFV_matrix VBES
USA_trkdpit_IntFV_matrix VDEP
USA_trkdpit_IntFV_matrix VDES
USA_trkdpit_IntFV_matrix VIAC
USA_trkdpit_IntFV_matrix VIAT
USA_trkdpit_IntFV_matrix VIEX
USA_trkdpit_IntFV_matrix VITN
USA_trkdpit_IntFV_matrix VPTI
USA_trkdpit_IntFV_matrix VTLD
USA_trkdpit_IntFV_matrix VTOL
USA_trkdpit_IntFV_matrix XNIC
USA_trkdpit_IntFV_matrix DataDate
USA_trkdpit_IntFV_matrix_2 VGWI
USA_trkdpit_IntFV_matrix_2 VSCP
USA_trkdpit_IntFV_matrix_2 DataDate

Sorting algorithms

#include <iostream>
using namespace std;
// ascending order
template<class T>
bool ascending(T first, T second){
	return first<=second;
}
// descending order
template<class T>
bool descending(T first, T second){
	return first>=second;
}
// swap two elements of a given array
template<class T>
void swap(T arr[],unsigned ii,unsigned jj){
	T temp;
	temp=arr[ii];
	arr[ii]=arr[jj];
	arr[jj]=temp;
}
// bubble sort
/*
The idea is: For a particular ii, compare it with all the next element, if there is any element that breaks out the expected order than swap positions
*/
template<class T>
void bubbleSort(T arr[],unsigned size,bool(*comparison)(T,T)){
	for (unsigned ii=0;ii<size-1;++ii){
		for (unsigned jj=ii+1;jj<size;++jj){
			if (!comparison(arr[ii],arr[jj])) swap(arr,ii,jj);
		}
	}
}
// insertion sort
/*
The idea is: For a particular ii, compare it with the previous subarray
*/
template<class T>
void insertionSort(T arr[],unsigned size,bool(*comparison)(T,T)){
	for(unsigned ii=0;ii<size;++ii){ 		unsigned jj=ii; 		while (jj>0){
			if (!comparison(arr[jj-1],arr[jj])) swap(arr,jj-1,jj);
			jj--;
		}
	}
}
// selection sort
/*
The idea is: For a particular ii, seek for the min(max) of the subarray after it, if the found element is different from ii, then swap
*/
template<class T>
void selectionSort(T arr[],unsigned size,bool(*comparison)(T,T)){
	for(unsigned ii=0;ii<size-1;++ii){
		unsigned iMin=ii;
		for (unsigned jj=ii+1;jj<size;++jj){
			if (!comparison(arr[iMin],arr[jj])) iMin=jj;
		}
		if (iMin!=ii) swap(arr,iMin,ii);
	}
}
//merge sort
/*
The idea is: divide and conquer.
*/
// merge function
template<class T>
void merge(T arr[],unsigned start,unsigned mid,unsigned end){
	unsigned ii(start),jj(mid+1),kk(0);
	T temp[end-start+1];
	while (ii<=mid && jj<=end){
		if (arr[ii]<arr[jj]){
			temp[kk]=arr[ii];
			ii++;
		}else{
			temp[kk]=arr[jj];
			jj++;
		}
		kk++;
	}
	if (ii<=mid){
		for (unsigned tt=ii;tt<=mid;++tt,++kk){
			temp[kk]=arr[tt];
		}
	}
	if (jj<=end){
		for(unsigned tt=jj;tt<=end;++tt,++kk){
			temp[kk]=arr[tt];
		}
	}
	for (unsigned tt=0;tt<kk;++tt){
		arr[start+tt]=temp[tt];
	}
}
// recursion function
template<class T>
void mergeSort(T arr[],unsigned start,unsigned end){
	if (start<end){
		unsigned mid=(start+end)/2;
		mergeSort(arr,start,mid);
		mergeSort(arr,mid+1,end);
		merge(arr,start,mid,end);
	}
}
// Shell sort
/*
The idea is: Develop from insertion sort and use gap to avoid moving too far
*/
template<class T>
void shellSort(T arr[],unsigned size){
	for (unsigned gap=size/2;gap>0;gap/=2){
		cout<<"ga="<<gap<<endl;
		for (unsigned ii=gap;ii<size;++ii){
			cout<<"ii="<<ii<<endl; 			T temp=arr[ii]; 			unsigned jj; 			for(jj=ii;jj>=gap && arr[jj-gap]>temp;jj-=gap){
				cout<<"jj="<<jj<<endl;
				arr[jj]=arr[jj-gap];
			}
			arr[jj]=temp;
		}
	}
}

Linked List

LinkedList.h

#ifndef LINKEDLIST_H
#define LINKEDLIST_H
struct Link {
	int num;
	Link* next;
};
class LinkedList{
private:
	Link *first,*last;
public:
	LinkedList();	// default constructor
	LinkedList(unsigned size,int uniformValue); // initialize a list with size element of uniformValue
	LinkedList(int *start, int *end); // initialize a list from start to end (not included end)
	void push_front(int value);	// add new item to the front of the list
	void push_back(int value);	// add new item to the end of the list
	int size();					// return the size of the list
	void display();				// display content of the list
	int operator [](unsigned index);	// overloading operator []
	int front();		// return the first element of the list
	int back(); 		// return the last element of the list
};
#endif

LinkedList.cc

#include <iostream>
#include <climits>
#include "LinkedList.h"
using namespace std;
//default constructor
LinkedList::LinkedList():first(NULL),last(NULL){}
// initialize a list with size element of uniformValue
LinkedList::LinkedList(unsigned size,int uniformValue){
	Link* arr=new Link[size];
	for (unsigned ii=0;ii<size;++ii){
		arr[ii].num=uniformValue;
		if (ii<size-1) arr[ii].next=arr+ii+1;
		else arr[ii].next=NULL;
	}
	first=arr;
	last=arr+size-1;
}
// initialize a list from start to end (not included end)
LinkedList::LinkedList(int *start, int *end){
	int size=end-start;
	Link* arr=new Link[size];
	for (unsigned ii=0;ii<size;++ii){
		arr[ii].num=*(start+ii);
		if (ii<size-1) arr[ii].next=arr+ii+1; 		else arr[ii].next=NULL; 	} 	first=arr; 	last=arr+size-1; } // add a new item to the front of the list void LinkedList::push_front(int value){ 	Link* pt=new Link;	//create a new atom  	pt->num=value;
	pt->next=first;
	first=pt;
	if (last==NULL) last=first; // if there is only one entity in the list so first=last
}
// add a new item to the back for the list
void LinkedList::push_back(int value){
	Link* pt =new Link;
	pt->num=value;
	pt->next=NULL;
	if (last==NULL) {
		last=pt;
		first=last;
	}else{
		last->next=pt;
		last=pt;
	}
}
// return the size of the list
int LinkedList::size(){
	Link* pt(first);
	int count(0);
	while(pt!=NULL){
		count++;
		pt=pt->next;
	}
	return count;
}
// display the content of the list
void LinkedList::display(){
	Link* pt(first);
	while(pt!=NULL){
		cout<<"["<<pt->num<<"]"; 		pt=pt->next;
	}
	cout<<endl; } // overloading operator [] int LinkedList::operator [] (unsigned index){ 	Link* pt(first); 	int count(0); 	while(pt!=NULL){ 		if (count==index) { 			return pt->num;
			break;
		}
		count++;
		pt=pt->next;
	}
	if (pt==NULL) return INT_MAX;
}
// return the first element of the list
int LinkedList::front(){
	if (first==NULL) return INT_MAX;
	return first->num;
}
// return the last element of the list
int LinkedList::back(){
	if (last==NULL) return INT_MAX;
	return last->num;
}

Integer in binary representation

#include <iostream>
#include <list>
using namespace std;
void print(const list<int>& li){
	list<int>::const_iterator it;
	short countT(0);
	for(it=li.begin();it!=li.end();++it){
		cout<<*it;
		countT++;
		if (!(countT%4)) cout<<" ";
	}
	cout<<endl;
}
list<int> PoDeToBi(int num){
	list<int> result(16,0);
	list<int>::reverse_iterator rit(result.rbegin());
	while (num!=0 && rit!=result.rend()){
		*rit=num%2;
		num/=2;
		++rit;
	}
	return result;
}
list<int> SumOfBi(const list<int> B1,const list<int> B2){
	list<int> result(16,0);
	list<int>::const_reverse_iterator crit1(B1.rbegin());
	list<int>::const_reverse_iterator crit2(B2.rbegin());
	list<int>::reverse_iterator ritR(result.rbegin());
	int remT(0);
	while (crit1!=B1.rend() && crit2!=B2.rend() && ritR!=result.rend()){
		if (remT+*crit1+*crit2<=1){
			*ritR=*crit1+*crit2+remT;
			remT=0;
		}
		else {
			*ritR=remT+*crit1+*crit2-2;
			remT=1;
		}
		crit1++;
		crit2++;
		ritR++;
	}
	return result;
}
list<int> NeDeToBi(int num){
	list<int> result(16,0);
	result=PoDeToBi(-num);
	list<int>::iterator it;
	for(it=result.begin();it!=result.end();++it){
		if (*it==0) *it=1;
		else *it=0;
	}
	result=SumOfBi(result,PoDeToBi(1));
	return result;
}
int BiToDe(const list<int>& Bi){
	int sum=0;
	list<int>::const_iterator it(Bi.begin());
	if (*it==0){
		it++;
		while(it!=Bi.end()){
			sum=sum*2+*it;
			++it;
		}
		return sum;
	}else{
		list<int> BiT(Bi);
		list<int>::iterator itT;
		for(itT=BiT.begin();itT!=BiT.end();++itT){
			if (*itT==0) *itT=1;
			else *itT=0;
		}
		itT=BiT.begin(); itT++;
		while(itT!=BiT.end()){
			sum=sum*2+*itT;
			++itT;
		}
		return -(sum+1);
	}
}
int main(){
	int a(23),b(15),c(-100);;
	list<int> la,lb,lc;
	la=PoDeToBi(a);
	lb=PoDeToBi(b);
	lc=NeDeToBi(c);
	print(la);print(lb);print(lc);
	cout<<BiToDe(la)<<endl;
	cout<<BiToDe(lb)<<endl;
	cout<<BiToDe(lc)<<endl;
}

Algorithm: Mutating Sequence Operations

#include <iostream>
#include <iomanip>
#include <algorithm> //copy, copy_backward, swap, iter_swap, swap_ranges, transform, replace, replace_if, replace_copy, replace_copy_if, fill, fill_n, generate, generate_n, remove, remove_if, remove_copy, remove_copy_if, unique, unique_copy, reverse, reverse_copy, rotate, rotate_copy, random_shuffle, partition, stable_partition
#include <utility>
#define LIMIT 6
#define LIMIT2 8
#define FIND_ELEMENT 11
using namespace std;
/*
Function declaration
*/
void add(int&); //add value to each array element
void print(const int[], const int&); // print arrays
bool isOdd(const int&); // check if element is odd
bool isConsecutive(const int&, const int&); // check if two numbers are consecutive
bool isMoreThan3(const int&,const int&); // check if twi numbers are more or less than 3
int add1(const int&); // add value to each array element but return a value
int mul1(const int&, const int&); // multiply two integers
bool isNeg(const int&); // check if the argument is negative
int gogo();
/*
Main function
*/
int main() {
    int* pt;
    int arr[]={2,3,5,6,7,8};
    int arr2[]={1,2,3,4,5,6,7,8};
    int arr3[]={-6,-5,-4,-3,-2,-1};
    int arr4[]={1,2,3,4,5,6};
    cout<<"Two original arrays:"<<endl;
    print(arr,LIMIT);
    print(arr2,LIMIT2);
    //copy
    cout<<"COPY OPERATION"<<endl;
    copy(arr,arr+LIMIT,arr2);
    cout<<"Two modified arrays:"<<endl;
    print(arr,LIMIT);
    print(arr2,LIMIT2);
    //copy_backward
    cout<<"COPY_BACKWARD OPERATION"<<endl;
    cout<<"Two original arrays:"<<endl;
    print(arr,LIMIT);
    print(arr2,LIMIT2);
    copy_backward(arr,arr+LIMIT,arr2+LIMIT2);
    cout<<"Two modified arrays:"<<endl;
    print(arr,LIMIT);
    print(arr2,LIMIT2);
    //swap
    cout<<"SWAP OPERATION"<<endl;
    cout<<"Two original arrays:"<<endl;
    print(arr3,LIMIT);
    print(arr4,LIMIT);
    swap(arr3,arr4);
    cout<<"Two modified arrays:"<<endl;
    print(arr3,LIMIT);
    print(arr4,LIMIT);
    //iter_swap
    cout<<"ITER_SWAP OPERATION"<<endl;
    cout<<"Two original arrays:"<<endl;
    print(arr3,LIMIT);
    print(arr4,LIMIT);
    iter_swap(arr3+2,arr4+2);
    cout<<"Two modified arrays:"<<endl;
    print(arr3,LIMIT);
    print(arr4,LIMIT);
    //swap_ranges
    cout<<"SWAP_RANGES OPERATION"<<endl;
    cout<<"Two original arrays:"<<endl;
    print(arr3,LIMIT);
    print(arr4,LIMIT);
    swap_ranges(arr3,arr3+2,arr4+3);
    cout<<"Two modified arrays:"<<endl;
    print(arr3,LIMIT);
    print(arr4,LIMIT);
    //transform
    cout<<"TRANSFORM OPERATION"<<endl;
    cout<<"The original array:"<<endl;
    print(arr3,LIMIT);
    print(arr4,LIMIT);
    cout<<"The first implementation of transform operation"<<endl;
    transform(arr3,arr3+LIMIT,arr3,add1);
    cout<<"The modified array:"<<endl;
    print(arr3,LIMIT);
    cout<<"The second implementation of transform operation"<<endl;
    transform(arr3,arr3+LIMIT,arr4,arr3,mul1);
    cout<<"The modified array:"<<endl;
    print(arr3,LIMIT);
    //replace
    cout<<"REPLACE OPERATION"<<endl;
    cout<<"The original array:"<<endl;
    print(arr3,LIMIT);
    replace(arr3,arr3+LIMIT,-3,4);
    cout<<"The modified array:"<<endl;
    print(arr3,LIMIT);
    //replace_if
    cout<<"REPLACE_IF OPERATION"<<endl;
    cout<<"The original array:"<<endl;
    print(arr3,LIMIT);
    replace_if(arr3,arr3+LIMIT,isNeg,300);
    cout<<"The modified array:"<<endl;
    print(arr3,LIMIT);
    //replace_copy
    cout<<"REPLACE_COPY OPERATION"<<endl;
    cout<<"The original array:"<<endl;
    print(arr3,LIMIT);
    print(arr4,LIMIT);
    replace_copy(arr3,arr3+LIMIT,arr4,4,1000);
    cout<<"The modified array:"<<endl;
    print(arr3,LIMIT);
    print(arr4,LIMIT);
    // fill
    cout<<"FILL OPERATIOM"<<endl;
    cout<<"The original array:"<<endl;
    print(arr3,LIMIT);
    fill(arr3,arr3+3,1986);
    cout<<"The modified array:"<<endl;
    print(arr3,LIMIT);
    // fill_n
    cout<<"FILL_N OPERATIOM"<<endl;
    cout<<"The original array:"<<endl;
    print(arr3,LIMIT);
    fill_n(arr3+3,3,1991);
    cout<<"The modified array:"<<endl;
    print(arr3,LIMIT);
    // generate
    cout<<"GENERATE OPERATION"<<endl;
    cout<<"The original array:"<<endl;
    print(arr3,LIMIT);
    generate(arr3,arr3+LIMIT,gogo);
    cout<<"The modified array:"<<endl;
    print(arr3,LIMIT);
    // unique
    int arr5[]={1,1,3,4,4,5};
    cout<<"UNIQUE OPERATION"<<endl;
    cout<<"The original array:"<<endl;
    print(arr5,LIMIT);
    pt=unique(arr5,arr5+LIMIT);
    cout<<"The modified array:"<<endl;
    print(arr5,LIMIT);
    cout<<pt-arr5+1<<"position has been checked for their duplication"<<endl;
}
/*
Function definition1
*/
void add(int& i) {
	i += 3;
}
void print(const int arr[], const int& SIZE) {
	cout << "[";
	for (unsigned i = 0; i<SIZE; ++i) {
		cout << setw(2) << arr[i];
		if (i != SIZE - 1) cout << ",";
	}
	cout << "]" << endl;
}
bool isOdd(const int& i) {
	return i % 2;
}
bool isConsecutive(const int& i, const int& j) {
	return abs(i - j) == 1 ? true : false;
}
bool isMoreThan3(const int& i, const int& j){
    return abs(i-j)<3?true:false;
}
int add1(const int& i){
    return i+3;
}
int mul1(const int& i, const int& j){
    return i*j;
}
bool isNeg(const int& i){
    return i<0;
}
int gogo(){
    return 1212;
}

Algorithm: non-mutating sequence operations

Non-mutating sequence operations: for_each, find, find_if, adjacent_find, count, count_if, mismatch, equal, search
#include <iostream>
#include <iomanip>
#include <algorithm> //for_each, find, find_if, adjacent_find, count, count_if, mismatch, equal, search
#include <utility>
#define LIMIT 6
#define FIND_ELEMENT 11
using namespace std;
/*
Function declaration
*/
void add(int&); //add value to each array element
void print(const int[], const int&); // print arrays
bool isOdd(const int&); // check if element is odd
bool isConsecutive(const int&, const int&); // check if two numbers are consecutive
bool isMoreThan3(const int&,const int&); // check if twi numbers are more or less than 3
/*
Main function
*/
int main() {
	int arr[] = { 2,4,6,6,11,8 };
	int arr2[] = { 2,4,6,4,8,12 };
	int arr3[] = { 2,4,5,4,9,12 };
	int arr4[] = { 6,4,8 };
	int *pt;
	cout << "Original array:" << endl;
	print(arr, LIMIT);
	cout << "Add 3 to each array element:" << endl;
	//for_each(first,last,functor)
	for_each(arr, arr + LIMIT, add);
	print(arr, LIMIT);
	//find(first,last,value)
	pt = find(arr, arr + LIMIT, FIND_ELEMENT);
	if (pt != arr + LIMIT) cout << FIND_ELEMENT << " is found in the given array and it stands at " << pt - arr + 1 << " position of the array" << endl;
	else cout << FIND_ELEMENT << " is NOT found in the given array" << endl;
	//find if(first,last,predicate)
	pt = find_if(arr, arr + LIMIT, isOdd);
	if (pt != arr + LIMIT) cout << "The first odd element stands at " << pt - arr + 1 << " position of the array" << endl;
	else cout << "There is not any odd element in the given array" << endl;
	//adjacent_find (first,last,[predicate]);
	pt = adjacent_find(arr, arr + LIMIT);
	if (pt != arr + LIMIT) cout << "There are some adjacent elements that are equal, the first element is at " << pt - arr + 1 << " position of the array" << endl;
	else cout << "There are not any adjacent elements that are equal in the given array" << endl;
	pt = adjacent_find(arr, arr + LIMIT, isConsecutive);
	if (pt != arr + LIMIT) cout << "There are some adjacent elements that are less or greater another 1, the first element is at " << pt - arr + 1 << " position of the array" << endl;
	else cout << "There are not any adjacent elements that are less or greater another 1 in the given array" << endl;
	//count
	cout << "There are " << count(arr, arr + LIMIT, 9) << " that equal(s) to 9 in the given array" << endl;
	cout << "There are " << count_if(arr, arr + LIMIT, isOdd) << " odd elements in the given array" << endl;
	// mismatch (first 1,last 1, first 2, [predicate])
	cout<<"Two compared arrays:"<<endl;
	print(arr2,LIMIT);
	print(arr3,LIMIT);
	pair<int*, int*> pa;
	pa = mismatch(arr2, arr2 + LIMIT, arr3);
	if (pa.first==arr2+LIMIT) cout<<"Two given arrays are the same. They are totally matched"<<endl;
	else cout<<"Two given arrays are mismatched. The different members are: "<<*pa.first<<" in the first and "<<*pa.second<<" in the second one"<<endl;
	pa = mismatch(arr2, arr2 + LIMIT, arr3,isMoreThan3);
	if (pa.first==arr2+LIMIT) cout<<"Two given arrays are not far than 3."<<endl;
	else cout<<"Two given arrays are mismatched in limit of 3. The different members are: "<<*pa.first<<" in the first and "<<*pa.second<<" in the second one"<<endl;
	// equal
	if (equal(arr2,arr2+LIMIT,arr3)) cout<<"Two arrays are totally matched"<<endl;
	else cout<<"Two arrays are different"<<endl;
	// search
	cout<<"The third array is:"<<endl;
	print(arr4,3);
	pt=search(arr3,arr3+LIMIT,arr4,arr4+3);
	if (pt!=arr3+LIMIT) cout<<"The partern is found in the first array at "<<pt-arr3+1<<" position"<<endl;
	else cout<<"The partern is NOT found"<<endl;
    pt=search(arr3,arr3+LIMIT,arr4,arr4+3,isMoreThan3);
    if (pt!=arr3+LIMIT) cout<<"The partern with a predication is found in the first array at "<<pt-arr3+1<<" position"<<endl;
    else cout<<"The partern is NOT found"<<endl;
}
/*
Function definition1
*/
void add(int& i) {
	i += 3;
}
void print(const int arr[], const int& SIZE) {
	cout << "[";
	for (unsigned i = 0; i<SIZE; ++i) {
		cout << setw(2) << arr[i];
		if (i != SIZE - 1) cout << ",";
	}
	cout << "]" << endl;
}
bool isOdd(const int& i) {
	return i % 2;
}
bool isConsecutive(const int& i, const int& j) {
	return abs(i - j) == 1 ? true : false;
}
bool isMoreThan3(const int& i, const int& j){
    return abs(i-j)<3?true:false;
}
OUTPUT
Original array:
[ 2, 4, 6, 6,11, 8]
Add 3 to each array element:
[ 5, 7, 9, 9,14,11]
11 is found in the given array and it stands at 6 position of the array
The first odd element stands at 1 position of the array
There are some adjacent elements that are equal, the first element is at 3 position of the array
There are not any adjacent elements that are less or greater another 1 in the given array
There are 2 that equal(s) to 9 in the given array
There are 5 odd elements in the given array
Two compared arrays:
[ 2, 4, 6, 4, 8,12]
[ 2, 4, 5, 4, 9,12]
Two given arrays are mismatched. The different members are: 6 in the first and 5 in the second one
Two given arrays are not far than 3.
Two arrays are different
The third array is:
[ 6, 4, 8]
The partern is NOT found
The partern with a predication is found in the first array at 3 position

Convert data types in C++ (Implicit ways)

Type convertion is a very common in programming. Let’s see ways to solve this issue in C++: implicit and explicit ways. In this entry we will take a look at implicit ways.

Implicit ways

Normal types

It is likely automatical conversion. Something is like promotion when int type is converted to float or double type, char to int, short to int or long. By this type of conversion value of variables is not be lost. For example: 6 -> 6.0. or ‘c’->”c” [see the following example]

#include<iostream>
using namespace std;
int main(){
    int var1(6);
    char var2('a');
    double var1_1(var1);
    int var2_1(var2);
    cout<<var1_1<<endl;
    cout<<var2_1<<endl;
}

The output is:

6
97

However if two types are not compatible original values can be lost, e.g. in case convert form int to unsigned, or double to int [see the following example].

#include<iostream>
using namespace std;
int main(){
    double var1(6.5);
    int var2(-1);
    int var1_1(var1);
    unsigned var2_1(var2);
    cout<<var1_1<<endl;
    cout<<var1_2<<endl; } 

The output is:

6 4294967295

Form 6.5, it leaves 0.5 to be an integer and becomes 6. As for -1, it become the largest unsigned integer (4 bytes – 1 byte is 8 bits)-> 2^32-1= 4294967296-1=4294967295.

Pointers

I wonder if a pointer of int can be converted to a pointer of double? Let’s give it a go.

The answer is no, we can’t. There is an error prompt of the following code:

#include<iostream>
using namespace std;
int main(){
    int var1(6);
    int* p_var1=&amp;amp;amp;var1;
    double* var1_1;
    var1_1=p_var1;
    cout<<*var1_1<<endl;
}

 

error: cannot convert 'int*' to 'double*' in assignment|

As for pointers, there are two important types of them is NULL POINTER and VOID POINTER.

NULL POINTER POINTS TO “NOWHERE” WHILE VOID POINTER POINTS TO “SOMEWHERE” WITHOUT SPECIFYING DATA THAT ADDRESS CONTAINS.

As for converting pointer types, there are some rules to consider:

  1. Null pointer can be converted to any pointer types
  2. Pointer to any type can be converted to void pointer.

Let’s see some illustrations of the above rules:

#include<iostream>
using namespace std;
int main(){
    int* p1=nullptr;
    double* p2=nullptr;
    int var1=5;
    double var2=5.5;
    p1=&var1;
    p2=&var2;
    cout<<"address of var1="<<p1<<"\tvalue of var="<<*p1<<endl;
    cout<<"address of var2="<<p2<<"\tvalue of var="<<*p2<<endl;
}