#include<iostream> using namespace std; class peak { int n,*p,*q; public: void get() { cout<<"\nenter how many elements u want in array"; cin>>n; } void create() { p=new int[n]; q=new int[n]; } void find(); void show(); void input(); void del() { delete []p; delete []q; } }; void peak:: find() { int j=0,i=1; if(p[0]>p[1]) q[j++]=p[0]; for(i=1;i<n-1;i++) { if(p[i]>p[i-1] && p[i]>p[i+1]) q[j++]=p[i]; } if(p[i]>p[i-1]) q[j]=p[i]; } void peak::show() { cout<<"\nthe peak elements are:"; for(int i=0;i<n;i++) //showing different garbage for *(q+i):6750404 and q[i]:3080388 cout<<q[i]<<"\t"; } void peak::input() { cout<<"\nenter elements "; for(int i=0;i<n;i++) cin>>p[i]; } int main() { peak p; p.get(); p.create(); p.input(); p.find(); p.show(); p.del(); return 0; }
Quote:How to initialise dynamic integer array with 0 when using new pointer in C++
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)