Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main()
- {
- int n,i,newIndex,newInput,temp,choice;
- cout << "Insert Array size: ";
- cin >> n;
- int *num=new int[n];
- cout << "Insert Array Elements...." <<endl;
- for(i=0; i<n; i++)
- {
- cin >> num[i];
- }
- cout << "For PUSH press 1 & For POP press 2"<<endl;
- cout << "Choise: ";
- cin >> choice;
- if(choice == 1)
- {
- num[n+1];
- cout << "Input at which index new Data PUSH: ";
- cin >> newIndex;
- cout << "Input New element: ";
- cin >> newInput;
- for(i=n+1; i!=newIndex; i--)
- {
- num[i+1] = num[i];
- }
- temp = num[newIndex];
- num[newIndex] = newInput;
- num[newIndex+1] = temp;
- cout << "New Array is....." <<endl;
- for(i=0; i<n+1; i++)
- {
- cout << num[i] <<endl;
- }
- }
- else if(choice == 2)
- {
- cout << "Input at which index new Data POP: ";
- cin >> newIndex;
- for(i=newIndex; i<n; i++)
- {
- num[i] = num[i+1];
- }
- num[n-1];
- cout << "New Array is....." <<endl;
- for(i=0; i<n-1; i++)
- {
- cout << num[i] <<endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment