This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdexcept> | |
#include <iostream> | |
#include <memory> | |
#include <cstring> | |
#include <cmath> | |
using namespace std; | |
template<class T> | |
class RingBuffer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstring> | |
#include <string> | |
using namespace std; | |
// returns true if A is a fading palindome | |
bool ifp(char* A) { | |
int i, n = strlen(A); | |
for (i = 0; i < n/2; ++i) { | |
// we need to check the palindome invariant A[i] == A[n-i-1] and |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void makeBowTie(int h) { | |
int i, j, k, s; | |
for (i = 1; i <= h; ++i) { | |
s = 2*i-1; | |
s = h - abs(h - s); | |
for (j = 0; j < s; ++j) cout << '*'; | |
for (j = 0; j < 2*h - 2*s; ++j) cout << ' '; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
// 1 - 3 + 5 - 7 + 9 ... +/- n | |
// recursive | |
int f1(int n) { | |
if (n == 1) return 1; | |
if (n % 2 == 0) n--; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int at(int* arr, int n, int k, int m) { | |
return arr[((m + (n - (k % n))) % n)]; | |
} | |
int rotated_binary_search(int* arr, int n, int k, int key) { | |
int low = 0, high = n-1, mid, v; | |
while (low <= high) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
// returns the element at index m in arr after k rotations | |
int at(int* arr, int n, int k, int m) { | |
return arr[((m + (n - (k % n))) % n)]; | |
} | |
int main() { | |
int n, k, q, i, j, m; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
struct node{ | |
int data; | |
node* next; | |
}; | |
node* NewNode(int data){ | |
node* n=new node; | |
n->data=data; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstring> | |
using namespace std; | |
void downup(const char str[]) { | |
int n = strlen(str); | |
int i, j; | |
for (i = 0; i < n; ++i) { | |
for (j = 0; j < n-i; ++j) | |
cout << str[j]; | |
cout << '\n'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NumberGuessing.cpp : Defines the entry point for the console application. | |
// | |
#include "stdafx.h" | |
#include <iostream> | |
#include <ctime> | |
#include <vector> | |
#include <numeric> | |
#include <limits> | |
#include <string> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ListNode { | |
int val; | |
struct ListNode* next; | |
ListNode(int val) : val(val), next(0) {} | |
}; | |
struct ListNode* newNode(int data) { | |
return new struct ListNode(data); | |
} |