From 3030a0f8a4c54f89cc7e71c95e96227745b0dd09 Mon Sep 17 00:00:00 2001 From: Kuldip Kumar Date: Sun, 15 Oct 2017 13:12:13 +0530 Subject: [PATCH 01/19] RSA algorithm implemented in python in encryption_algorithms directory --- encryption_algorithms/RSA_algorithm.py | 88 ++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 encryption_algorithms/RSA_algorithm.py diff --git a/encryption_algorithms/RSA_algorithm.py b/encryption_algorithms/RSA_algorithm.py new file mode 100644 index 000000000..5ccea69f6 --- /dev/null +++ b/encryption_algorithms/RSA_algorithm.py @@ -0,0 +1,88 @@ +#RSA encryption algorithm + +def main(): + n = e = d = 0 + while 1: + print(""" + 1. Set Public Key + 2. Encode + 3. Decode + 0. Quit + Your choice? """, end = "") + choice = int(input()) + if not choice: + return + if choice == 1: + n, e, d = set_keys() + if choice == 2: + if not n: + n = int(input("Public Key: ")) + e = int(input("e: ")) + encode(n, e) + if choice == 3: + if not d: + n, e, d = set_keys() + decode(d, n) + +def set_keys(): + """This fuction asks for 2 primes. + It sets a public key and an encoding number, 'e'.""" + p = int(input("prime(p): ")) + q = int(input("prime(q): ")) + n = p * q + m = (p - 1) * (q - 1) + e = get_e(m) + print("N = ", n, "\ne = ", e) + d = get_d(e, m) + while d < 0: + d += m + return [n, e, d] + +def encode(n, e): + """This function asks for a number and encodes it using 'n' and 'e'.""" + while 1: + c = int(input("Number to encode: ")) + if not c: + return + print(pow(c, e, n)) + +def decode(d, n): + """This function asks for a number and decodes it using 'd' and 'n'.""" + while 1: + c = int(input("Number to decode: ")) + if not c: + return + else: + print(pow(c, d, n)) + +def even(x): + """True if x is even.""" + return x % 2 == 0 + +def get_e(m): + """Finds an e coprime with m.""" + e = 2 + while gcd(e, m) != 1: + e += 1 + return e + +def gcd(a,b): + """Euclid's Algorithm: Takes two integers and returns gcd.""" + while b > 0: + a, b = b, a % b + return a + +def get_d(e, m): + """Takes encoding number, 'e' and the value for 'm' (p-1) * (q-1). + Returns a decoding number.""" + x = lasty = 0 + lastx = y = 1 + while m != 0: + q = e // m + e, m = m, e % m + x, lastx = lastx - q*x, x + y, lasty = lasty - q*y, y + return lastx + +if __name__ == "__main__": + main() \ No newline at end of file From b4cbdaaba56a8abfaa45fa8831b10dc605da4e74 Mon Sep 17 00:00:00 2001 From: nghiaxlee Date: Sun, 15 Oct 2017 09:59:23 +0200 Subject: [PATCH 02/19] done merge sort --- merge_sort.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 merge_sort.cpp diff --git a/merge_sort.cpp b/merge_sort.cpp new file mode 100644 index 000000000..2b5e4ad7b --- /dev/null +++ b/merge_sort.cpp @@ -0,0 +1,51 @@ +#include + +using namespace std; + +int a[100005]; +int n; + +void Merge(int a[], int l, int m, int r) { + int i1, i2, pos; + int n1 = m - l + 1; + int n2 = r - m; + int L[n1], R[n2]; + + for(int i = 0; i < n1; ++i) + L[i] = a[l + i]; + for(int i = 0; i < n2; ++i) + R[i] = a[m + 1 + i]; + + i1 = i2 = 0; // index of array 1 and 2 + pos = l; // index of megred array + while (i1 < n1 && i2 < n2) { + if (L[i1] <= R[i2]) a[pos] = L[i1++]; + else a[pos] = R[i2++]; + ++pos; + } + while (i1 < n1) a[pos] = L[i1++], ++pos; + while (i2 < n2) a[pos] = R[i2++], ++pos; + +} + +void MergeSort(int a[], int l, int r) { + if (l < r) { + int m = (l + r) / 2; + + //Sort 2 parts + MergeSort(a, l, m); + MergeSort(a, m + 1, r); + Merge(a, l, m, r); + } +} + +int main() { + ios_base::sync_with_stdio(false); cin.tie(NULL); + cin >> n; + for(int i = 1; i <= n; ++i) cin >> a[i]; + + MergeSort(a, 1, n); + + for(int i = 1; i <= n; ++i) cout << a[i] << ' '; + return 0; +} \ No newline at end of file From 03b772757c54a3990aa46526185c2d85ce7c9cd5 Mon Sep 17 00:00:00 2001 From: bamsarts Date: Sun, 15 Oct 2017 15:39:56 +0700 Subject: [PATCH 03/19] add program to count the age person in c++ --- count_the_age_person/count_the_age_person.cpp | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 count_the_age_person/count_the_age_person.cpp diff --git a/count_the_age_person/count_the_age_person.cpp b/count_the_age_person/count_the_age_person.cpp new file mode 100644 index 000000000..abfa8dd63 --- /dev/null +++ b/count_the_age_person/count_the_age_person.cpp @@ -0,0 +1,23 @@ +using namespace std; + +#include + +int main() +{ + int birthmonth,birthyear; + int currentmonth,currentyear; + int agey,agem; + cout<<"\n\n\t\t\tCount the age person\n\n"; + cout<<"Enter Your Birth Year(Eg:1989):"; + cin>>birthyear; + cout<<"\n\nEnter Your Birth Month(Eg:7):"; + cin>>birthmonth; + cout<<"\nEnter The Current Month(Eg:7):"; + cin>>currentmonth; + cout<<"\nEnter The Current Year(Eg:2010):"; + cin>>currentyear; + agey=currentyear-birthyear; + agem=12-birthmonth; + cout<<"\n\n\t\tYour Age is "< Date: Sun, 15 Oct 2017 09:20:21 +0000 Subject: [PATCH 04/19] Added intendation and comments --- hello_world/hello_world.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hello_world/hello_world.cpp b/hello_world/hello_world.cpp index d44063bf3..4017aaa69 100644 --- a/hello_world/hello_world.cpp +++ b/hello_world/hello_world.cpp @@ -2,7 +2,8 @@ using namespace std; -int main() { - cout << "Hello world!" << endl; +int main() +{ + cout << "Hello world!" << endl;//cout statement is used for printing a given output to the screen return 0; } From 9148803719e16eb7057ca85714f21a19f331e865 Mon Sep 17 00:00:00 2001 From: Mahak Bagha Date: Sun, 15 Oct 2017 15:09:09 +0530 Subject: [PATCH 05/19] BFS in undirected graph --- BFS/BFS.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 BFS/BFS.cpp diff --git a/BFS/BFS.cpp b/BFS/BFS.cpp new file mode 100644 index 000000000..0bf36e40e --- /dev/null +++ b/BFS/BFS.cpp @@ -0,0 +1,66 @@ +#include +#define ll long long + +using namespace std; +vector gr[1010]; + +void bfs(ll u,ll V,bool vis[]) +{ + + + queue q; + vis[u]=true; + q.push(u); + while(!q.empty()) + { + ll ver=q.front(); + q.pop(); + cout<>v>>e; + while(e--) + { + ll u,v; + cin>>u>>v; + gr[u].push_back(v); + gr[v].push_back(u); + + } + ll src; + cin>>src; + bfsMain(src,v); + return 0; +} +/* +8 9 +0 1 +0 2 +1 3 +2 4 +1 4 +3 4 +3 5 +4 5 +6 7 +0 +*/ From e5c5f65d933978545ecb12c964abb013b1d09df2 Mon Sep 17 00:00:00 2001 From: rsm23 Date: Sun, 15 Oct 2017 11:13:36 +0100 Subject: [PATCH 06/19] Adding the fibonacci sequence program in C and a README file Adding the fibonacci sequence program in C and a README file --- fib/README.md | 1 - fibonacci/README.md | 17 +++++++++++++++++ fibonacci/fibonacci.c | 22 ++++++++++++++++++++++ {fib => fibonacci}/fibonacci.cpp | 0 4 files changed, 39 insertions(+), 1 deletion(-) delete mode 100644 fib/README.md create mode 100644 fibonacci/README.md create mode 100644 fibonacci/fibonacci.c rename {fib => fibonacci}/fibonacci.cpp (100%) diff --git a/fib/README.md b/fib/README.md deleted file mode 100644 index 096b5d67e..000000000 --- a/fib/README.md +++ /dev/null @@ -1 +0,0 @@ -The following c++ proram will take the nth term as input and will give the value of at that nth term as output. diff --git a/fibonacci/README.md b/fibonacci/README.md new file mode 100644 index 000000000..ec414cc5f --- /dev/null +++ b/fibonacci/README.md @@ -0,0 +1,17 @@ +## The Fibonacci Sequence +### Algorithm + +The Fibonacci Sequence is the series of numbers: + +`0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...` + +The next number is found by adding up the two numbers before it. + +* The 2 is found by adding the two numbers before it (1+1) +* The 3 is found by adding the two numbers before it (1+2), +* And the 5 is (2+3), +* and so on! + +### Output of the program +* `Enter the number of terms: 10` +* `Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,` diff --git a/fibonacci/fibonacci.c b/fibonacci/fibonacci.c new file mode 100644 index 000000000..5fe391b8e --- /dev/null +++ b/fibonacci/fibonacci.c @@ -0,0 +1,22 @@ +#include + int main() + { + int i, n, t1 = 0, t2 = 1, nextTerm; + + + printf("Enter the number of terms: "); + scanf("%d", &n); + + + printf("Fibonacci Series: "); + + + for (i = 1; i <= n; ++i) + { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + return 0; + } diff --git a/fib/fibonacci.cpp b/fibonacci/fibonacci.cpp similarity index 100% rename from fib/fibonacci.cpp rename to fibonacci/fibonacci.cpp From 4f031ad708b6f741c738aa834f3c4a893f8c85c5 Mon Sep 17 00:00:00 2001 From: t2013anurag Date: Sun, 15 Oct 2017 15:53:51 +0530 Subject: [PATCH 07/19] multiple fixes #63 --- .DS_Store | Bin 0 -> 6148 bytes {fib => fibonacci}/README.md | 0 {fib => fibonacci}/fibonacci.cpp | 0 hello_world/.DS_Store | Bin 0 -> 6148 bytes hello_world_haskell/helloWorld.hs | 1 - 5 files changed, 1 deletion(-) create mode 100644 .DS_Store rename {fib => fibonacci}/README.md (100%) rename {fib => fibonacci}/fibonacci.cpp (100%) create mode 100644 hello_world/.DS_Store delete mode 100644 hello_world_haskell/helloWorld.hs diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b28bc055fa746c16193e737f9159005fe740cd56 GIT binary patch literal 6148 zcmeHK-EPw`82!9;ETuy01=4nz8ze3&)D=cA5K@+PLX}`cWWWWWE@{ddk;PS#5+ufi&I-~=9we#Qa0X?8wbV^}2=KUb%0V2gR zaS!R{PigR$vk%ddx0L;DfnBB76j4B&67s2!D=PQLHWwH*8q$DbT%3ATAWz{hJSF?| zcdVeuM*7{p2ctO3@@De~TUo8FU0JuPRjYc2(*91dHl!s zgJ;p8=+&?9@g(=7WRT8-sm;!nNS+$GN4a+EC6u86+i1oon66k20DU?eGGI<05R!}Vs zzW7NH99yHKai$P=U`$bgipum6gDE=dZ5`)moGDavV*2pGbk9tmP?+o;?b|Y(n4{3- zMggNhS%Fnmtc(4B|NQfRnPf^v0i(dBQh-%DUdP2N>Am&L%Za_#Mmk0kCgNraB?Xz@ ij-?~E;w>a;xMvFo=xCfNL=DXR2uK-BW)%3R3j6{=n8MKj literal 0 HcmV?d00001 diff --git a/fib/README.md b/fibonacci/README.md similarity index 100% rename from fib/README.md rename to fibonacci/README.md diff --git a/fib/fibonacci.cpp b/fibonacci/fibonacci.cpp similarity index 100% rename from fib/fibonacci.cpp rename to fibonacci/fibonacci.cpp diff --git a/hello_world/.DS_Store b/hello_world/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..254ec6f8d9dab025ea9562f19381f8b72188614b GIT binary patch literal 6148 zcmeHK&2G~`5T0!VIH1s|AhkzdkT^srO({84NLDC^-jIUm0Z?k!QDZP(%XY9z2=aw@ zXn6x3g(u)axN(8m*#-O)BcBk09clMl&+a!9fA)B@0Ki6bcL$&g00uUJt*h9rFflJ$ z#nzOkgUBcbhY6&>Ap*a$T067?T7kb!0a3dhn86e)*2l{IRlhFWfs;d@pEy2ua20+c z*n7m=-^l1jHtLxWLReydDY38DvQL2*xv-Di^IYb7?hN7*_hV!3i!zsOHReX(6!Vf= z&3N>`pcb=3GV=l;*J?L6_O>7;w}0S^+}3#L(S`LiQ0aCti7 z^T3TM&LcaSA(s+Oy4#DzU~jKy4u*qe&s+?L{hoPu_ug`87+be??jIh%I(xHtyL@+n zf}t_oh{!e+{(uiSXn6at$5G((;1n4m+GefvA)LVg%LK6`ym;mE!v8+T?y4B{>g8kP z%k)TXvZ6?9zf6WyOUam4Fm2qv=r1ohAv;zON0^<8%ViRa7%p}sM13NkbAhys= zhGTJ-5FAsXr7)9-GiXdw5hazWBLA)y6#!;D>I-xMij((Gt1G6OR zUMrv#C@QcnFS}y@e^`J1FOu|?RzNH8Pbt7!2jc^AW>9-;<>tg*YhpXbCQPi$BoYNX jwH?zyY{lEy$Z*aS14K( Date: Sun, 15 Oct 2017 11:27:56 +0100 Subject: [PATCH 08/19] Hello World Java https://github.com/hacktoberfest17/programming/issues/54 --- hello_world/hello_world.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 hello_world/hello_world.java diff --git a/hello_world/hello_world.java b/hello_world/hello_world.java new file mode 100644 index 000000000..1a9b666fb --- /dev/null +++ b/hello_world/hello_world.java @@ -0,0 +1,7 @@ +public class HelloWorld { + + public static void main(String[] args) { + System.out.println("Hello World!"); + } + +} From b49784c9841674fc49766f41b2d338789e8dde4c Mon Sep 17 00:00:00 2001 From: Kanishk Singh Date: Sun, 15 Oct 2017 15:58:27 +0530 Subject: [PATCH 09/19] Added Bubble Sort in Python, #65 --- bubble_sort_python/bubble_sort.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 bubble_sort_python/bubble_sort.py diff --git a/bubble_sort_python/bubble_sort.py b/bubble_sort_python/bubble_sort.py new file mode 100644 index 000000000..0daba2ce1 --- /dev/null +++ b/bubble_sort_python/bubble_sort.py @@ -0,0 +1,15 @@ +'''Bubble Sort in Python''' + +def bubble_sort(alist): + for i in range(len(alist)-1,0,-1): + for j in range(i): + if alist[j]>alist[j+1]: + temp = alist[j] + alist[j] = alist[j+1] + alist[j+1] = temp + +if __name__ == '__main__': + #Sample data for sorting. + ALIST = [54, 26, 93, 17, 77, 31, 44, 55, 20] + bubble_sort(ALIST) + print(ALIST) From 01a9848171d43ebda1f6f7d53306d307f8e7fe75 Mon Sep 17 00:00:00 2001 From: t2013anurag Date: Sun, 15 Oct 2017 16:06:30 +0530 Subject: [PATCH 10/19] fix for #71 --- {bubble_sort_python => bubble_sort}/bubble_sort.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {bubble_sort_python => bubble_sort}/bubble_sort.py (100%) diff --git a/bubble_sort_python/bubble_sort.py b/bubble_sort/bubble_sort.py similarity index 100% rename from bubble_sort_python/bubble_sort.py rename to bubble_sort/bubble_sort.py From cd5e103c331fcdf2b615ae5d4ead2fddc72f6ee3 Mon Sep 17 00:00:00 2001 From: Swim Systems Date: Sun, 15 Oct 2017 12:39:47 +0200 Subject: [PATCH 11/19] Add fibonacci calculator written in Go --- fibonacci/fibonacci.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 fibonacci/fibonacci.go diff --git a/fibonacci/fibonacci.go b/fibonacci/fibonacci.go new file mode 100644 index 000000000..a2c2104c4 --- /dev/null +++ b/fibonacci/fibonacci.go @@ -0,0 +1,26 @@ +package main + +import "fmt" + +func fibonacci() func() int { + a, b := 0, 1 + return func() int { + a = a + b + a, b = b, a + return a + } +} + +func main() { + var n int + fmt.Print("Enter value: ") + fmt.Scanf("%d", &n) + + f := fibonacci() + var fib int + for i := 0; i < n; i++ { + fib = f() + fmt.Printf("%d, ", fib) + } + fmt.Printf("\nfib(%d) = %d\n", n, fib) +} From 2acbc89f34df1e39351d43588c0c1bd7a06a463d Mon Sep 17 00:00:00 2001 From: Mahak Bagha Date: Sun, 15 Oct 2017 16:18:35 +0530 Subject: [PATCH 12/19] dfs done --- dfs/dfs.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ dfs/readme.txt | 9 +++++++ 2 files changed, 75 insertions(+) create mode 100644 dfs/dfs.cpp create mode 100644 dfs/readme.txt diff --git a/dfs/dfs.cpp b/dfs/dfs.cpp new file mode 100644 index 000000000..0bf36e40e --- /dev/null +++ b/dfs/dfs.cpp @@ -0,0 +1,66 @@ +#include +#define ll long long + +using namespace std; +vector gr[1010]; + +void bfs(ll u,ll V,bool vis[]) +{ + + + queue q; + vis[u]=true; + q.push(u); + while(!q.empty()) + { + ll ver=q.front(); + q.pop(); + cout<>v>>e; + while(e--) + { + ll u,v; + cin>>u>>v; + gr[u].push_back(v); + gr[v].push_back(u); + + } + ll src; + cin>>src; + bfsMain(src,v); + return 0; +} +/* +8 9 +0 1 +0 2 +1 3 +2 4 +1 4 +3 4 +3 5 +4 5 +6 7 +0 +*/ diff --git a/dfs/readme.txt b/dfs/readme.txt new file mode 100644 index 000000000..378153158 --- /dev/null +++ b/dfs/readme.txt @@ -0,0 +1,9 @@ +Depth First Traversal + +Depth First Traversal for a graph is similar to Depth First Traversal of a tree. +The only catch here is, unlike trees, graphs may contain cycles, so we may come to the same node again. +To avoid processing a node more than once, we use a boolean visited array. + +The function dfsMain is used for cases when all vertices are not reachable from the starting vertex. + +Time Complexity: O(V+E) where V is number of vertices in the graph and E is number of edges in the graph. From 98193744b6c99a83e5ffeff0ab46935f4a7834b2 Mon Sep 17 00:00:00 2001 From: Swim Systems Date: Sun, 15 Oct 2017 12:51:29 +0200 Subject: [PATCH 13/19] Remove .DS_Store files and add them to the .gitignore file --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 1 + hello_world/.DS_Store | Bin 6148 -> 0 bytes 3 files changed, 1 insertion(+) delete mode 100644 .DS_Store create mode 100644 .gitignore delete mode 100644 hello_world/.DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index b28bc055fa746c16193e737f9159005fe740cd56..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK-EPw`82!9;ETuy01=4nz8ze3&)D=cA5K@+PLX}`cWWWWWE@{ddk;PS#5+ufi&I-~=9we#Qa0X?8wbV^}2=KUb%0V2gR zaS!R{PigR$vk%ddx0L;DfnBB76j4B&67s2!D=PQLHWwH*8q$DbT%3ATAWz{hJSF?| zcdVeuM*7{p2ctO3@@De~TUo8FU0JuPRjYc2(*91dHl!s zgJ;p8=+&?9@g(=7WRT8-sm;!nNS+$GN4a+EC6u86+i1oon66k20DU?eGGI<05R!}Vs zzW7NH99yHKai$P=U`$bgipum6gDE=dZ5`)moGDavV*2pGbk9tmP?+o;?b|Y(n4{3- zMggNhS%Fnmtc(4B|NQfRnPf^v0i(dBQh-%DUdP2N>Am&L%Za_#Mmk0kCgNraB?Xz@ ij-?~E;w>a;xMvFo=xCfNL=DXR2uK-BW)%3R3j6{=n8MKj diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..e43b0f988 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/hello_world/.DS_Store b/hello_world/.DS_Store deleted file mode 100644 index 254ec6f8d9dab025ea9562f19381f8b72188614b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK&2G~`5T0!VIH1s|AhkzdkT^srO({84NLDC^-jIUm0Z?k!QDZP(%XY9z2=aw@ zXn6x3g(u)axN(8m*#-O)BcBk09clMl&+a!9fA)B@0Ki6bcL$&g00uUJt*h9rFflJ$ z#nzOkgUBcbhY6&>Ap*a$T067?T7kb!0a3dhn86e)*2l{IRlhFWfs;d@pEy2ua20+c z*n7m=-^l1jHtLxWLReydDY38DvQL2*xv-Di^IYb7?hN7*_hV!3i!zsOHReX(6!Vf= z&3N>`pcb=3GV=l;*J?L6_O>7;w}0S^+}3#L(S`LiQ0aCti7 z^T3TM&LcaSA(s+Oy4#DzU~jKy4u*qe&s+?L{hoPu_ug`87+be??jIh%I(xHtyL@+n zf}t_oh{!e+{(uiSXn6at$5G((;1n4m+GefvA)LVg%LK6`ym;mE!v8+T?y4B{>g8kP z%k)TXvZ6?9zf6WyOUam4Fm2qv=r1ohAv;zON0^<8%ViRa7%p}sM13NkbAhys= zhGTJ-5FAsXr7)9-GiXdw5hazWBLA)y6#!;D>I-xMij((Gt1G6OR zUMrv#C@QcnFS}y@e^`J1FOu|?RzNH8Pbt7!2jc^AW>9-;<>tg*YhpXbCQPi$BoYNX jwH?zyY{lEy$Z*aS14K( Date: Sun, 15 Oct 2017 13:08:32 +0200 Subject: [PATCH 14/19] Add linked list implementation in Go --- linked_list/linked_list.go | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 linked_list/linked_list.go diff --git a/linked_list/linked_list.go b/linked_list/linked_list.go new file mode 100644 index 000000000..e837954fd --- /dev/null +++ b/linked_list/linked_list.go @@ -0,0 +1,53 @@ +package main + +import "fmt" + +type Node struct { + prev *Node + next *Node + key interface{} +} + +type LinkedList struct { + head *Node + tail *Node +} + +func (L *LinkedList) Insert(key interface{}) { + list := &Node{ + next: L.head, + key: key, + } + if L.head != nil { + L.head.prev = list + } + L.head = list + + l := L.head + for l.next != nil { + l = l.next + } + L.tail = l +} + +func (l *LinkedList) Show() { + list := l.head + for list != nil { + fmt.Printf("%+v", list.key) + if list.next != nil { + fmt.Printf(" --> ") + } + list = list.next + } + fmt.Println() +} + +func main() { + l := LinkedList{} + l.Insert(1) + l.Insert(2) + l.Insert(3) + l.Insert(4) + l.Insert(5) + l.Show() +} From f7f0c7dd13005f3d776e7f9cc07250599822fa34 Mon Sep 17 00:00:00 2001 From: Le Minh Nghia Date: Sun, 15 Oct 2017 13:30:21 +0200 Subject: [PATCH 15/19] Remove extra line, cout new line --- merge_sort.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/merge_sort.cpp b/merge_sort.cpp index 2b5e4ad7b..2993ae0b3 100644 --- a/merge_sort.cpp +++ b/merge_sort.cpp @@ -25,7 +25,6 @@ void Merge(int a[], int l, int m, int r) { } while (i1 < n1) a[pos] = L[i1++], ++pos; while (i2 < n2) a[pos] = R[i2++], ++pos; - } void MergeSort(int a[], int l, int r) { @@ -42,10 +41,12 @@ void MergeSort(int a[], int l, int r) { int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; - for(int i = 1; i <= n; ++i) cin >> a[i]; + for(int i = 1; i <= n; ++i) + cin >> a[i]; MergeSort(a, 1, n); - for(int i = 1; i <= n; ++i) cout << a[i] << ' '; + for(int i = 1; i <= n; ++i) + cout << a[i] << '\n'; return 0; -} \ No newline at end of file +} From 9f79ade5c3572d3a76ff75946f1b7773b4e3801c Mon Sep 17 00:00:00 2001 From: PiyushPawar17 Date: Sun, 15 Oct 2017 17:17:24 +0530 Subject: [PATCH 16/19] Added Linear Search in Cpp --- linear_search/linear_search.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 linear_search/linear_search.cpp diff --git a/linear_search/linear_search.cpp b/linear_search/linear_search.cpp new file mode 100644 index 000000000..66ff4fc5e --- /dev/null +++ b/linear_search/linear_search.cpp @@ -0,0 +1,26 @@ +// Linear Search in C++ +#include +using namespace std; + +int main() { + + // Random data to search from + int searchArray[] = {10, 23, 89, 126, 51, 7, 45, 55}; + int size = sizeof(searchArray) / sizeof(searchArray[0]); + int search = 51; // Number to search + int index = -1; + + for (int i = 0; i < size; i++) { + if (searchArray[i] == search) { + index = i; + break; + } + } + + if (index >= 0) + cout << search << " found at index " << index << endl; + else + cout << search << " not found in the array" << endl; + + return 0; +} From 9943745cdc9f9682fe7666a6476712b58ae697e9 Mon Sep 17 00:00:00 2001 From: PiyushPawar17 Date: Sun, 15 Oct 2017 17:49:14 +0530 Subject: [PATCH 17/19] Added Bubble Sort in Cpp --- bubble_sort/bubble_sort.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 bubble_sort/bubble_sort.cpp diff --git a/bubble_sort/bubble_sort.cpp b/bubble_sort/bubble_sort.cpp new file mode 100644 index 000000000..259b3cf60 --- /dev/null +++ b/bubble_sort/bubble_sort.cpp @@ -0,0 +1,28 @@ +// Bubble Sort in C++ +#include +using namespace std; + +int main() { + + int array[] = {10, 6, 56, 45, 37, 7, 23}; // Array to sort + int size = sizeof(array) / sizeof(array[0]); + + while (true) { + bool sorted = true; + for (int i = 0; i < size; i++) { + if (array[i] > array[i + 1]) { + int temp = array[i]; + array[i] = array[i + 1]; + array[i + 1] = temp; + sorted = false; + } + } + if (sorted) break; + } + + // Printing sorted array + for (int i = 0; i < size; i++) + cout << array[i] << " "; + + return 0; +} From 9c7787b293f77055cc0aba11d9d3247f9890352f Mon Sep 17 00:00:00 2001 From: Kuldip Kumar Date: Sun, 15 Oct 2017 18:34:38 +0530 Subject: [PATCH 18/19] Updated RSA_algorithm.py --- encryption_algorithms/RSA_algorithm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/encryption_algorithms/RSA_algorithm.py b/encryption_algorithms/RSA_algorithm.py index 5ccea69f6..1d1156e8f 100644 --- a/encryption_algorithms/RSA_algorithm.py +++ b/encryption_algorithms/RSA_algorithm.py @@ -85,4 +85,4 @@ def get_d(e, m): return lastx if __name__ == "__main__": - main() \ No newline at end of file + main() From 4addee4adc930814b895e31e7ab2e83ec97b04f7 Mon Sep 17 00:00:00 2001 From: Bambang Supriadi Date: Sun, 15 Oct 2017 20:08:10 +0700 Subject: [PATCH 19/19] fixing some request --- count_the_age_person/count_the_age_person.cpp | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/count_the_age_person/count_the_age_person.cpp b/count_the_age_person/count_the_age_person.cpp index abfa8dd63..47c29a294 100644 --- a/count_the_age_person/count_the_age_person.cpp +++ b/count_the_age_person/count_the_age_person.cpp @@ -4,20 +4,27 @@ using namespace std; int main() { - int birthmonth,birthyear; - int currentmonth,currentyear; - int agey,agem; + int BirthMonth, BirthYear; + int CurrentMonth, CurrentYear; + int AgeYear, AgeMonth; + cout<<"\n\n\t\t\tCount the age person\n\n"; cout<<"Enter Your Birth Year(Eg:1989):"; - cin>>birthyear; + cin>>BirthYear; + cout<<"\n\nEnter Your Birth Month(Eg:7):"; - cin>>birthmonth; + cin>>BirthMonth; + cout<<"\nEnter The Current Month(Eg:7):"; - cin>>currentmonth; + cin>>CurrentMonth; + cout<<"\nEnter The Current Year(Eg:2010):"; - cin>>currentyear; - agey=currentyear-birthyear; - agem=12-birthmonth; - cout<<"\n\n\t\tYour Age is "<>CurrentYear; + + AgeYear=CurrentYear-BirthYear; + AgeMonth=12-BirthMonth; + + cout<<"\n\n\t\tYour Age is "<