#include<stdio.h> #include<conio.h> struct proc { int id; int burst; int at; }; int main() { int n,i,j,total_waiting_time,waiting_time; printf("Enter the number of processess: "); scanf("%d",&n); struct proc p[n],temp; f or(i=0;i<n;i++) { p[i].id=i; printf("Enter the arrival time of the process: "); scanf("%d",&p[i].at); printf("Enter the burst time of the process: "); scanf("%d",&p[i].burst); } for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(p[j].at<p[i].at) { ...
#include <bits/stdc++.h> using namespace std ; stack < int > rev ( stack < int > s ) { int size = s . size (), x , y , t ; stack < int > s2 ; size -= 1 ; while ( size --) { t = size + 1 ; x = s . top (); s . pop (); while ( t --) { s2 . push ( s . top ()); s . pop (); } ...
Example 1: Input: root = [1,2,3,4,5,6,7] Output: [1,#,2,3,#,4,5,6,7,#] Explanation: Given the above perfect binary tree (Figure A), your function should populate each next pointer to point to its next right node, just like in Figure B. The serialized output is in level order as connected by the next pointers, with '#' signifying the end of each level. Example 2: Input: root = [] Output: [] class Solution { public: Node * connect ( Node * root ) { Node * p1 = root , * p2 ; while ( p1 != NULL ) { p2 = p1 ; while ( p2 != NULL ) { if ( p2 -> left ) p2 -> left -> next = p2 -> right ; ...
#include <bits/stdc++.h> using namespace std ; #define max 10000 int main () { int n , c , j , k , x , i ; int a [ max ]; cout << "Enter the number: " ; cin >> n ; j = 0 ; // j will be pointing to new index created to stored carry a [ 0 ] = 1 ; for ( i = 2 ; i <= n ; i ++) { c = 0 ; //carry when each number of array is multiplied by i //(i is a...
#include <iostream> #include <vector> using namespace std ; struct TreeNode { int val ; TreeNode * left ; TreeNode * right ; TreeNode () : val ( 0 ), left ( nullptr ), right ( nullptr ) {} TreeNode ( int x ) : val ( x ), left ( nullptr ), right ( nullptr ) {} TreeNode ( int x , TreeNode * left , TreeNode * right ) : val ( x ), left ( left ), right ( right ) {} }; TreeNode * BuildTree () { int d ; cin >> d ; if ( d == -...
https://practice.geeksforgeeks.org/problems/image-multiplication0627/1 Input: 1 / \ 3 2 / \ / \ 7 6 5 4 / \ \ / \ \ 11 10 15 9 8 12 Output: 332 Explanation: Sum = (1*1) + (3*2) + (7*4) + (6*5) + (11*12) + (15*9) = 332 class Solution { public: void treeHelper ( Node * a , Node * b , long long int & ans ) { if (a== NULL ||b== NULL ) return ; long long int temp=( a -> data * b -> data )%( 1000000007 ); ans=(ans+temp)%( 1000000007 ); treeHelper ( a -> left , b -> right , ans); treeHelper ( a -> right , b -> left , ans); } ...
Comments
Post a Comment