Skip to main content

Posts

Showing posts from May, 2021

Queue using C++(Struct)

 Q). Implement Queue using struct in c++ => Prog : #include<iostream> #include<iomanip> using namespace std; #define MAX 5 typedef struct queue_type{   int arr[MAX]={0,0,0,0,0};   int frontSide;   int rearSide; }node; void insertVal(int item,node * ptr); int deleteVal(node *ptr); void display(node *ptr); int main(){ char ch; int choice,item; node queueNode; queueNode.frontSide=-1; queueNode.rearSide=-1; do{     cout<<"\n************* please press below key for that option *************\n\n";     cout<<"1.Insert Value in Queue \n";     cout<<"2.Delete Value in Queue \n";     cout<<"3.Display \n";     cout<<"choice : ";     cin>>choice;     switch(choice){      case 1: cout<<"Enter the data : ";              cin>>item;              insertVal(item,&queueNode);              break;      case 2: item=deleteVal(&queueNode);              cout<<"Pop eleme

Stack using C++(Struct)

 Q). Implement Stack push and pop function using struct in C++ =>Program : #include<iostream> #include<iomanip> using namespace std; #define MAX 5 typedef struct stack_node{   int arr[MAX];   int top; }node; void push(int item,node *ptr); int pop(node *ptr); void display(node *ptr); int main(){ int item,choice; char ch; node myStack; myStack.top=-1; do{     cout<<"\n************* please press below key for that option *************\n\n";     cout<<"1.Push Value in stack \n";     cout<<"2.Pop Value in stack \n";     cout<<"3.Display \n";     cin>>choice;     switch(choice){      case 1: cout<<"Enter the data : ";              cin>>item;              push(item,&myStack);              break;      case 2: item=pop(&myStack);              cout<<"Pop element : "<<item<<endl;              break;       case 3: display(&myStack);               break;

Direct Method of Mean (C++ Program)

 Q). Write the C++ Program for direct method of Mean => Prog : #include<iostream> #include <iomanip> using namespace std; int main(){ int n; double sumF=0,sumFX=0; cout<<"Enter the number input  : "; cin>>n; double number[n]; double freq[n]; for(int i=0; i<n; i++){     cout<<"Number["<<i+1<<"] : ";     cin>>number[i];     cout<<"frequency["<<i+1<<"] : ";     cin>>freq[i]; } cout<<"\n\n"<<setw(20)<<"Number"<<setw(10)<<"|"<<setw(20)<<"Frequency"<<endl<<endl; for(int i=0; i<n; i++){     cout<<setw(20)<<number[i]<<setw(10)<<"|"<<setw(20)<<freq[i]<<endl;;     sumF=sumF+freq[i]; } cout<<"\n****************      After Calculation      ********************\n"; cout<<"\n\n"<<setw(20)&l

Arrays: Left Rotation

  A   left rotation   operation on an array shifts each of the array's elements     unit to the left. For example, if     left rotations are performed on array   , then the array would become   . Note that the lowest index item moves to the highest index in a rotation. This is called a   circular array . Given an array   of   integers and a number,  , perform   left rotations on the array. Return the updated array to be printed as a single line of space-separated integers. Function Description Complete the function  rotLeft  in the editor below. rotLeft has the following parameter(s): int a[n]:  the array to rotate int d:  the number of rotations Returns int a'[n]:  the rotated array Input Format The first line contains two space-separated integers   and  , the size of   and the number of left rotations. The second line contains   space-separated integers, each an  . Constraints Sample Input 5 4 1 2 3 4 5 Sample Output 5 1 2 3 4 Explanation When we perform   left rotations, the