Category : arrays

I implemented binary search in two ways and wondering which is more efficient? please help me know which is more efficient and how can it further be optimized? I am a beginner in programming. approach 1; #include<iostream> using namespace std; bool BinarySearch(int*a,int n,int s ){ if(n==1){ if(a[0]==s) return true; else return false; } else{ if(s<a[n/2]){ ..

Read more

I am given an array of positive integers. What are the minimum operations required such that the array becomes continuous. In one Operation we can Replace one number with any Integer. For e.g input: arr = [6,4,1,7,10], output: 2 we can make the array: [6,4,5,7,8] Source: Windows Que..

Read more

So, I have a two dimensional array as follows: char board[3][3] = {{‘1’, ‘2’, ‘3’}, {‘4’, ‘5’, ‘6’}, {‘7’, ‘8’, ‘9’}}; and I’m accessing its elements in this way, for instance: cout << board[0][0] << board[0][1] << board[0][2] << "n"; cout << board[1][0] << board[1][1] << board[1][2] << "n"; cout << board[2][0] << board[2][1] << ..

Read more

I’m writing a program to have a class that represents both the suit and rank of a deck of playing cards. I made an array of structs(which contains 2 enums to represent the suit/rank values). class cardDeckClass { public: cardDeckClass(); void print(); private: typedef enum {CLUBS, DIAMONDS, HEARTS, SPADES} suits; typedef enum {ACE, KING, QUEEN, ..

Read more

I cannot solve the error – main.cpp:31:34: error: ‘sortBook’ was not declared in this scope in the line sortBook(arr,arr+n,comparator); I apologize for asking a question that should have a simple solution, but it’s driving me nuts. I’ve checked for all the common errors. #include<iostream> using namespace std; class BOOK{ private: char bookname[20]; float bookprice; public: ..

Read more