This file contains 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; | |
class node{ | |
public: | |
int data; | |
node* left; | |
node* right; | |
int height; | |
node(int data){ | |
this->data=data; |
This file contains 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; | |
class node{ | |
public: | |
int data; | |
node* left; | |
node* right; | |
node(int data){ | |
this->data=data; | |
this->left=nullptr; |
This file contains 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 <vector> | |
using namespace std; | |
void subString(string a, int n){ | |
int x=0, i=0, j=0; | |
vector<string> v; | |
string r=""; | |
r=r+a[0]; | |
v.push_back(r); | |
while(i<n){ |
This file contains 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; | |
bool ifAnagram(string s, string a){ | |
int c1[26]; // count of each character from a to z for string s | |
int c2[26]; // count of each character from a to z for string a | |
// if string lengths of s and that a are different then no anagram | |
if(s.length()!=a.length()){ | |
return false; | |
} | |
// initially c1, c2 store zero for every character |
This file contains 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; | |
// | |
int searchPattern(string s, string pattern){ | |
int n=s.length(); | |
int m=pattern.length(); | |
int i=0; | |
while(i<n){ | |
if(s[i]==pattern[0]){ // if char at index=0 of pattern equals char at index=i of main string | |
int j=0; |
This file contains 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 <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main(){ | |
FILE *ptr_file; // pointer to file | |
char buf[1000]; // stores each line of file | |
char file[100]="H/file.bin"; | |
ptr_file =fopen(file, "r"); // opens file in read mode | |
if (!ptr_file){ // checks if there is no file | |
return 1; |
This file contains 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
//-------------------- node.h-------------- | |
#ifndef NODE_H | |
#define NODE_H | |
#include <iostream> | |
using namespace std; | |
template <class T> | |
class node{ | |
public: | |
T data; | |
node<T>* next; |
This file contains 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
// If a project is big, then it may include more than one file. In fact, there may be hundreds of files. | |
// In C++, there is file called header file and another one called cpp file. They work together to accomplish something | |
// header file is where class/struct is defined and then there is another file, let's call it header_cpp, methods defined in header | |
//file are given bodies in header_cpp file. Finally there is a main file, let's call it, main.cpp, this is a driver file. | |
// Let's take an example | |
// --------HEADER FILE, test.h----------- | |
#ifndef TEST_H // include guard | |
#define TEST_H |
This file contains 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
// activity selection problem | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
void schedule(int* a, int* s, int* f, int n){ | |
vector<int> act; | |
act.push_back(0); | |
int ft=f[0]; |
This file contains 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; | |
// creates nodes to store vertices | |
class node{ | |
public: | |
int dest; | |
node* next; | |
}; | |
// creates adjacency list with head as node type | |
class adList{ |