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
from queue import Queue | |
def Bfs(G,src,des): | |
dist=[-1]*(len(G)+1) #create distance list for save dist | |
Q=Queue() #create a queue for maintaining tree level | |
dist[src]=0 #source dist set zero | |
Q.put(src) #insert source into queue | |
while(Q.empty()!=True): #iterate until queue is empty | |
u=Q.get() #get front node from queue & pop up | |
for v in G[u]: #explore all adjacency node of u | |
if(dist[v]==-1): #if v node isn't explore previous then its -1 |
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 <algorithm> | |
#include <vector> | |
using namespace std; | |
int main () | |
{ | |
int myints[] = {10,20,30,30,20,10,10,20,50,1,39,40}; | |
vector<int> v(myints,myints+12); | |
sort (v.begin(), v.end()); | |
vector<int>::iterator low,up; |
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<map> | |
using namespace std; | |
int main() | |
{ | |
map<char,int>Map; | |
for(char c='a';c<='j';c++) | |
{ | |
int value=(int)c; | |
Map[c]=value; |
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<map> | |
using namespace std; | |
int main() | |
{ | |
map<char,int>Map; | |
for(char c='a';c<='j';c++) | |
{ | |
int value=(int)c; | |
Map[c]=value; |
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<map> | |
using namespace std; | |
int main() | |
{ | |
map<char,int>Map; | |
map<char,int>::iterator it; | |
for(char c='a';c<='j';c++) | |
{ | |
int value=(int)c; |
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<set> | |
using namespace std; | |
int main() | |
{ | |
set<int>S; | |
set<int>::iterator it; | |
for(int i=1;i<100;i++) | |
{ | |
S.insert(i%10); |
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<queue> | |
#include<stdlib.h> | |
using namespace std; | |
int main() | |
{ | |
queue<int>Q; | |
for(int i=0;i<5;i++) | |
{ | |
int x=rand()%100; |
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<stack> | |
#include<stdlib.h> | |
using namespace std; | |
int main() | |
{ | |
stack<int>S; | |
for(int i=0;i<5;i++) | |
{ | |
int x=rand()%100; |
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<string> | |
#include<stdlib.h> | |
using namespace std; | |
int main() | |
{ | |
string str="somewhere, something incredible is waiting to be known."; | |
cout<<"Find some from first: "<<str.find("some")<<endl; |
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<string> | |
#include<stdlib.h> | |
using namespace std; | |
int main() | |
{ | |
string inp; | |
cin>>inp; | |
cout<<"First input: "<<inp<<endl; | |
cin.ignore(); |