Skip to content

Commit e68a391

Browse files
authored
Merge branch 'master' into Reverse_a_number_in_python
2 parents 6470ee5 + 47708ee commit e68a391

File tree

359 files changed

+18366
-78
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

359 files changed

+18366
-78
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
.DS_Store
2+
3+
# Dependencies
4+
node_modules/

Applet in java/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Applet Programming with Animation
2+
3+
When You run this code:
4+
on mouse click car(drawn on applet) will start moving (Animation in applet)

Applet in java/car.java

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
import java.applet.*;
2+
import java.awt.*;
3+
import java.awt.event.*;
4+
public class car extends Applet implements Runnable,MouseListener
5+
6+
7+
{
8+
int i=0,k=0,z=0;
9+
public void paint(Graphics g)
10+
{
11+
int x[]={200+i,300+i,400+i,500+i,500+i,0+i,0+i,100+i};
12+
int y[]={200,200,300,300,400,400,300,300};
13+
g.setColor(Color.RED);
14+
g.fillPolygon(x,y,8);
15+
g.setColor(Color.BLUE);
16+
g.drawPolygon(x,y,8);
17+
g.setColor(Color.WHITE);
18+
g.fillOval(80+i, 350, 80, 80);
19+
g.fillOval(320+i, 350, 80, 80);
20+
g.setColor(Color.GREEN);
21+
g.drawOval(80+i, 350, 80, 80);
22+
g.drawOval(320+i, 350, 80, 80);
23+
int x1[]={200+i,300+i,380+i,120+i};
24+
int y1[]={220,220,300,300};
25+
26+
g.setColor(Color.DARK_GRAY);
27+
g.fillPolygon(x1,y1,4);
28+
g.setColor(Color.MAGENTA);
29+
g.drawPolygon(x1,y1,4);
30+
31+
}
32+
void update()
33+
{
34+
35+
if(z%2!=0)
36+
{
37+
i=(i+1)%getWidth();
38+
}
39+
if(z%2==0)
40+
{
41+
42+
if(i==0)
43+
{
44+
i=getWidth();
45+
}
46+
i=(i-1);
47+
48+
}
49+
50+
}
51+
52+
Thread t;
53+
Thread t1;
54+
public void init()
55+
{
56+
t=new Thread(this);
57+
//t.setDaemon(true);
58+
t1=new Thread(this);
59+
//t1.setDaemon(true);
60+
addMouseListener(this);
61+
62+
63+
}
64+
public void run()
65+
{
66+
if(z%2==0)
67+
{
68+
while(true)
69+
{
70+
update();
71+
repaint();
72+
try
73+
{
74+
Thread.sleep(10);
75+
}
76+
catch(Exception e )
77+
{
78+
79+
}
80+
81+
}
82+
}
83+
84+
if(z%2!=0)
85+
{
86+
while(true)
87+
{
88+
update();
89+
repaint();
90+
try
91+
{
92+
Thread.sleep(10);
93+
}
94+
catch(Exception e )
95+
{
96+
97+
}
98+
}
99+
100+
}
101+
102+
}
103+
104+
public void mouseClicked(MouseEvent e)
105+
{
106+
107+
//if(k>0)
108+
//{
109+
//t.resume();
110+
111+
// }
112+
System.out.println("kkk = "+e);
113+
int x=e.getX();
114+
int y=e.getY();
115+
116+
z++;
117+
while(x>0&&x<getWidth())
118+
{
119+
120+
if(z%2!=0)
121+
{
122+
System.out.println(x);
123+
t.start();
124+
}
125+
if(z%2==0)
126+
{
127+
System.out.println(x);
128+
t1.start();
129+
}
130+
131+
}
132+
133+
134+
135+
}
136+
137+
138+
139+
@Override
140+
public void mouseEntered(MouseEvent arg0) {
141+
// TODO Auto-generated method stub
142+
143+
}
144+
145+
@Override
146+
public void mouseExited(MouseEvent arg0) {
147+
// TODO Auto-generated method stub
148+
149+
}
150+
151+
@Override
152+
public void mousePressed(MouseEvent arg0)
153+
{
154+
155+
156+
}
157+
@Override
158+
public void mouseReleased(MouseEvent arg0)
159+
{
160+
161+
}
162+
163+
164+
165+
166+
167+
}

BFS/BFS.cpp

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ vector<ll> gr[1010];
66

77
void bfs(ll u,ll V,bool vis[])
88
{
9-
10-
119
queue<ll> q;
1210
vis[u]=true;
1311
q.push(u);
@@ -16,21 +14,20 @@ void bfs(ll u,ll V,bool vis[])
1614
ll ver=q.front();
1715
q.pop();
1816
cout<<ver<<" ";
19-
for(ll i=0;i<gr[ver].size();i++)
20-
if(!vis[gr[ver][i]]){
17+
for(ll i=0; i<gr[ver].size(); i++)
18+
if(!vis[gr[ver][i]])
19+
{
2120
vis[gr[ver][i]]=true;
2221
q.push(gr[ver][i]);
23-
}
22+
}
2423
}
25-
26-
2724
}
2825
void bfsMain(ll src,ll V)
2926
{
30-
bool vis[V];
27+
bool vis[V];
3128
fill(vis,vis+V,false);
3229
bfs(src,V,vis);
33-
for(ll i=0;i<V;i++)
30+
for(ll i=0; i<V; i++)
3431
if(!vis[i])
3532
bfs(i,V,vis);
3633
}
@@ -51,16 +48,3 @@ int main()
5148
bfsMain(src,v);
5249
return 0;
5350
}
54-
/*
55-
8 9
56-
0 1
57-
0 2
58-
1 3
59-
2 4
60-
1 4
61-
3 4
62-
3 5
63-
4 5
64-
6 7
65-
0
66-
*/

BFS/README.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Breadth First Traversal
2+
3+
Breadth First Traversal for a graph is similar to Breadth First Traversal of a tree.
4+
The only catch here is, unlike trees, graphs may contain cycles, so we may come to the same node again.
5+
To avoid processing a node more than once, we use a boolean visited array. For simplicity, it is assumed that all vertices are reachable from the starting vertex.
6+
7+
The dfsMain function is used for the case if all vertices are not reachable from the starting vertex.
8+
9+
Time Complexity: O(V+E) where V is number of vertices in the graph and E is number of edges in the graph.

BST/createBST_From_sortedArray.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include<iostream>
2+
#include<stack>
3+
using namespace std;
4+
5+
// A BST node
6+
struct Node
7+
{
8+
int data;
9+
struct Node *left,*right;
10+
};
11+
12+
// A utility function to create new Node
13+
Node* newNode(int val)
14+
{
15+
Node* temp = new Node;
16+
temp->data = val;
17+
temp->left = temp->right = NULL;
18+
}
19+
20+
Node* createBST(int arr[],int l,int r)
21+
{
22+
if(l>r)
23+
return NULL;
24+
25+
int mid = (l+r)/2;
26+
27+
Node* root = newNode(arr[mid]);
28+
29+
root->left = createBST(arr,l,mid-1);
30+
root->right = createBST(arr,mid+1,r);
31+
32+
return root;
33+
34+
}
35+
36+
void inorderIterative(Node* root)
37+
{
38+
stack<Node*> s;
39+
40+
Node* current = root;
41+
42+
while(1)
43+
{
44+
if(current)
45+
{
46+
s.push(current);
47+
current = current->left;
48+
}
49+
else
50+
{
51+
if(!s.empty())
52+
{
53+
current = s.top();
54+
s.pop();
55+
cout<<current->data<<" ";
56+
current = current->right;
57+
}
58+
else
59+
{
60+
break;
61+
}
62+
}
63+
64+
}
65+
}
66+
67+
68+
int main()
69+
{
70+
71+
int arr[] = {1,2 ,3 ,4 ,5 ,6, 7,8,9,10,11,12};
72+
int size = sizeof(arr)/sizeof(arr[0]);
73+
74+
Node* root = createBST(arr,0,size-1);
75+
76+
inorderIterative(root);
77+
}

0 commit comments

Comments
 (0)