Skip to content
richagithub edited this page Dec 13, 2017 · 53 revisions

Welcome to the Codes wiki!

Why-cant-we-use-double-pointer-to-represent-two-dimensional-arrays? twoDArray.txt
Fast I/O Operation https://github.com/richagithub/Codes/blob/master/Fast_I%5CO.txt

 ios_base::sync_with_stdio(false);        
 cin.tie(NULL);

Tokenize a sting in c++? StringTokenizer.txt
How to scan integers until newline? answer
Find Largest and second largest int with O(n) answer
Sort a string or char array ? Answer
Permute given String and print all in lexicographically increasing order. TUTORIAL
Calculate power of 2 upto 100000 . program.cpp recursion dynamic programming
Input/Output with File in C++ codechef discuss

freopen("input.txt","r",stdin);//redirects standard input    
freopen("output.txt","w",stdout);//redirects standard output  

Operator Overloading
LaTreeX - online free TREE-PDF generatorLaTreeX - online free TREE-PDF generator
Recipe-to-improve-your-programmingmdotsabouri.blogspot.com

  • Strings
  • Graphs

Strings

Sr Challenge Solution
1 Seperate the Numbers solution.cpp
2 Weighted Unifrom Strings solution.cpp
3
4

Graphs

Sr Challenge Solution
1 Even Tree solution.cpp
2 Breadth First Search: Shortest Reach solution.cpp

Greedy

Sr Challenge Solution
1 buy-maximum-stocks solution.cpp

Dynamic Programming

Sr Challenge Solution
1 trader-profit solution.cpp

Codechef

Sr Challenge Solution
1 Chef and Sign Sequence july17.cpp

Operator Overloading

A simple and complete example

#include<iostream>
using namespace std; 
class Complex {
private:
    int real, imag;
public:
    Complex(int r = 0, int i =0)  {real = r;   imag = i;}
    // This is automatically called when '+' is used with
    // between two Complex objects
    Complex operator + (Complex const &obj) {
         Complex res;
         res.real = real + obj.real;
         res.imag = imag + obj.imag;
         return res;
    }
    void print() { cout << real << " + i" << imag << endl; }
};
int main()
{
    Complex c1(10, 5), c2(2, 4);
    Complex c3 = c1 + c2; // An example call to "operator+"
    c3.print();
}  

Output: 12 + i9

Global Operator Function

class Complex {
private:
    int real, imag;
public:
    Complex(int r = 0, int i =0)  {real = r;   imag = i;}
    void print() { cout << real << " + i" << imag << endl; }
 
// The global operator function is made friend of this class so
// that it can access private members
friend Complex operator + (Complex const &, Complex const &);
};
 
 
Complex operator + (Complex const &c1, Complex const &c2)
{
     return Complex(c1.real + c2.real, c1.imag + c2.imag);
}

Following is the list of operators that cannot be overloaded. . (dot) :: ?: sizeof

Clone this wiki locally