From 185c4bf5e8ecf5c064f9fabde09505004f8c6ba7 Mon Sep 17 00:00:00 2001 From: palak Date: Fri, 1 Oct 2021 11:24:15 +0530 Subject: [PATCH 1/9] Add initial folders and README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 58d0202..8e10f64 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# DS \ No newline at end of file +# REPOSITORY TO HOLD PROGRAMS FOR VARIOUS DATA STRUCTURES + +Pick a language of your choice and if you don't find a data structure implemented in the language feel free to contribute \ No newline at end of file From 4411679731dfe039a4c8ef64c785325a8cb9b9f7 Mon Sep 17 00:00:00 2001 From: saloniig Date: Fri, 1 Oct 2021 12:18:05 +0530 Subject: [PATCH 2/9] Updates code for list in python - Swap elements at given position - swap first and last element of a list --- Python/List/interchangefirstlastele.py | 18 ++++++++++++++++++ Python/List/swap2elements.py | 14 ++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 Python/List/interchangefirstlastele.py create mode 100644 Python/List/swap2elements.py diff --git a/Python/List/interchangefirstlastele.py b/Python/List/interchangefirstlastele.py new file mode 100644 index 0000000..48b5719 --- /dev/null +++ b/Python/List/interchangefirstlastele.py @@ -0,0 +1,18 @@ +# Python3 program to swap first +# and last element of a list + +# Swap function +def swapList(newList): + size = len(newList) + + # Swapping + temp = newList[0] + newList[0] = newList[size - 1] + newList[size - 1] = temp + + return newList + +# Driver code +newList = [12, 35, 9, 56, 24] + +print(swapList(newList)) diff --git a/Python/List/swap2elements.py b/Python/List/swap2elements.py new file mode 100644 index 0000000..4ca2b5f --- /dev/null +++ b/Python/List/swap2elements.py @@ -0,0 +1,14 @@ +# Python3 program to swap elements +# at given positions + +# Swap function +def swapPositions(list, pos1, pos2): + + list[pos1], list[pos2] = list[pos2], list[pos1] + return list + +# Driver function +List = [23, 65, 19, 90] +pos1, pos2 = 1, 3 + +print(swapPositions(List, pos1-1, pos2-1)) From 7806e664ee106a7de7809ecc8354c90d6e55b937 Mon Sep 17 00:00:00 2001 From: palak Date: Fri, 1 Oct 2021 14:10:10 +0530 Subject: [PATCH 3/9] Add a script to generate certificates --- certificate-generator/Manas Kumar.txt | 20 ++++++++++ certificate-generator/Niraj Kumar.txt | 20 ++++++++++ certificate-generator/Prakash Kumar.txt | 20 ++++++++++ certificate-generator/README.md | 21 +++++++++++ certificate-generator/input.txt | 1 + certificate-generator/main.py | 49 +++++++++++++++++++++++++ 6 files changed, 131 insertions(+) create mode 100644 certificate-generator/Manas Kumar.txt create mode 100644 certificate-generator/Niraj Kumar.txt create mode 100644 certificate-generator/Prakash Kumar.txt create mode 100644 certificate-generator/README.md create mode 100644 certificate-generator/input.txt create mode 100644 certificate-generator/main.py diff --git a/certificate-generator/Manas Kumar.txt b/certificate-generator/Manas Kumar.txt new file mode 100644 index 0000000..5ec30ed --- /dev/null +++ b/certificate-generator/Manas Kumar.txt @@ -0,0 +1,20 @@ + + ---------------------------------------------------------------------------- + | Certificate of Completion | + | | + | | + | This is to certify that Manas Kumar has successfully completed the | + | course in Micro Biology. | + | | + | | + | | + | | + | ______________________ _______________ | + | Signature of Instructor Signature of HOD | + | | + | | + | | + | | + | | + --------------------------------------------------------------------------- + \ No newline at end of file diff --git a/certificate-generator/Niraj Kumar.txt b/certificate-generator/Niraj Kumar.txt new file mode 100644 index 0000000..bc106a0 --- /dev/null +++ b/certificate-generator/Niraj Kumar.txt @@ -0,0 +1,20 @@ + + ---------------------------------------------------------------------------- + | Certificate of Completion | + | | + | | + | This is to certify that Niraj Kumar has successfully completed the | + | course in Micro Biology. | + | | + | | + | | + | | + | ______________________ _______________ | + | Signature of Instructor Signature of HOD | + | | + | | + | | + | | + | | + --------------------------------------------------------------------------- + \ No newline at end of file diff --git a/certificate-generator/Prakash Kumar.txt b/certificate-generator/Prakash Kumar.txt new file mode 100644 index 0000000..067c921 --- /dev/null +++ b/certificate-generator/Prakash Kumar.txt @@ -0,0 +1,20 @@ + + ---------------------------------------------------------------------------- + | Certificate of Completion | + | | + | | + | This is to certify that Prakash Kumar has successfully completed the | + | course in Micro Biology. | + | | + | | + | | + | | + | ______________________ _______________ | + | Signature of Instructor Signature of HOD | + | | + | | + | | + | | + | | + --------------------------------------------------------------------------- + \ No newline at end of file diff --git a/certificate-generator/README.md b/certificate-generator/README.md new file mode 100644 index 0000000..d6cb27d --- /dev/null +++ b/certificate-generator/README.md @@ -0,0 +1,21 @@ +## CERTIFICATE GENERATOR + + + +A python script to read names from a txt file and generate txt files in the same directory + + + +#### HOW TO RUN THE SCRIPT + +- extract the zip file + +- open the terminal and change directory to extracted zip folder + +- write comma separated names in input.txt ( a sample of it is added here ) + +- in the terminal type `python -u main.py` + +- if the input file exists and and it has names txt files with name as file name will be generated + +- for the sample input files, output certificates are attached diff --git a/certificate-generator/input.txt b/certificate-generator/input.txt new file mode 100644 index 0000000..f94f943 --- /dev/null +++ b/certificate-generator/input.txt @@ -0,0 +1 @@ +Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar,Prakash Kumar,Manas Kumar,Niraj Kumar \ No newline at end of file diff --git a/certificate-generator/main.py b/certificate-generator/main.py new file mode 100644 index 0000000..9b10b16 --- /dev/null +++ b/certificate-generator/main.py @@ -0,0 +1,49 @@ +''' +authored by palak thapar +''' + +import os +names = [] +input_file = 'input.txt' +try: + + if os.stat(input_file).st_size == 0: # check for an empty file + print('Sorry, the file {input_file} is empty'.format(input_file=input_file)) + else: + for line in open(input_file, 'r'): + for name in line.strip().split(','): + names.append(name) +except FileNotFoundError: # check for a non-existing file + msg = 'Sorry, the file {input_file} does not exist.'.format(input_file=input_file) + print(msg) + +for name in names: + with open(name + '.txt', 'w') as wp: + print("generating certificate for {name}".format(name=name)) + content = \ + ''' + ---------------------------------------------------------------------------- + | Certificate of Completion | + | | + | | + | This is to certify that {name} has successfully completed the | + | course in Micro Biology. | + | | + | | + | | + | | + | ______________________ _______________ | + | Signature of Instructor Signature of HOD | + | | + | | + | | + | | + | | + --------------------------------------------------------------------------- + ''' + wp.write(content.format(name=name)) # writing the content to each file + wp.close() # closing the file + + # a check for success + print("successfully generated certificate for {name}".format(name=name)) + print() From 51aa48da4a5eb8b8199b30d2852be45275a3df8d Mon Sep 17 00:00:00 2001 From: saloniig Date: Fri, 1 Oct 2021 14:19:00 +0530 Subject: [PATCH 4/9] Updates program of string in python - Reverse of string - Palindrome --- Python/Arrays/largestelementinarray.py | 1 - Python/Arrays/sumofarray.py | 1 - Python/string/checkpalindrome .py | 14 ++++++++++++++ Python/string/reversewords.py | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 Python/string/checkpalindrome .py create mode 100644 Python/string/reversewords.py diff --git a/Python/Arrays/largestelementinarray.py b/Python/Arrays/largestelementinarray.py index c1a58e3..d7f2fa8 100644 --- a/Python/Arrays/largestelementinarray.py +++ b/Python/Arrays/largestelementinarray.py @@ -22,4 +22,3 @@ def largest(arr,n): Ans = largest(arr,n) print ("Largest in given array is",Ans) -# This code is contributed by Smitha Dinesh Semwal diff --git a/Python/Arrays/sumofarray.py b/Python/Arrays/sumofarray.py index 172c509..2650692 100644 --- a/Python/Arrays/sumofarray.py +++ b/Python/Arrays/sumofarray.py @@ -29,4 +29,3 @@ def _sum(arr): # display sum print ('Sum of the array is ', ans) -# This code is contributed by Himanshu Ranjan diff --git a/Python/string/checkpalindrome .py b/Python/string/checkpalindrome .py new file mode 100644 index 0000000..9a13893 --- /dev/null +++ b/Python/string/checkpalindrome .py @@ -0,0 +1,14 @@ +# function which return reverse of a string + +def isPalindrome(s): + return s == s[::-1] + + +# Driver code +s = "malayalam" +ans = isPalindrome(s) + +if ans: + print("Yes") +else: + print("No") diff --git a/Python/string/reversewords.py b/Python/string/reversewords.py new file mode 100644 index 0000000..5067ced --- /dev/null +++ b/Python/string/reversewords.py @@ -0,0 +1,16 @@ +# Function to reverse words of string + +def rev_sentence(sentence): + + # first split the string into words + words = sentence.split(' ') + + # then reverse the split string list and join using space + reverse_sentence = ' '.join(reversed(words)) + + # finally return the joined string + return reverse_sentence + +if __name__ == "__main__": + input = 'geeks quiz practice code' + print (rev_sentence(input)) From 1f8e36f19711f2d34e6eab1b6fcc3bbcf0471d54 Mon Sep 17 00:00:00 2001 From: saloniig Date: Fri, 1 Oct 2021 14:28:39 +0530 Subject: [PATCH 5/9] Updates program for matrix in python - Multiply 2 matrix - Add 2 matrix --- Python/Matrix/add2matrix.py | 23 +++++++++++++++++++++++ Python/Matrix/multipy2matrix.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 Python/Matrix/add2matrix.py create mode 100644 Python/Matrix/multipy2matrix.py diff --git a/Python/Matrix/add2matrix.py b/Python/Matrix/add2matrix.py new file mode 100644 index 0000000..6a2eec8 --- /dev/null +++ b/Python/Matrix/add2matrix.py @@ -0,0 +1,23 @@ +# Program to add two matrices using nested loop + +X = [[1,2,3], + [4 ,5,6], + [7 ,8,9]] + +Y = [[9,8,7], + [6,5,4], + [3,2,1]] + + +result = [[0,0,0], + [0,0,0], + [0,0,0]] + +# iterate through rows +for i in range(len(X)): +# iterate through columns + for j in range(len(X[0])): + result[i][j] = X[i][j] + Y[i][j] + +for r in result: + print(r) diff --git a/Python/Matrix/multipy2matrix.py b/Python/Matrix/multipy2matrix.py new file mode 100644 index 0000000..8ca3429 --- /dev/null +++ b/Python/Matrix/multipy2matrix.py @@ -0,0 +1,28 @@ +# Program to multiply two matrices using nested loops + +# take a 3x3 matrix +A = [[12, 7, 3], + [4, 5, 6], + [7, 8, 9]] + +# take a 3x4 matrix +B = [[5, 8, 1, 2], + [6, 7, 3, 0], + [4, 5, 9, 1]] + +result = [[0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0]] + +# iterating by row of A +for i in range(len(A)): + + # iterating by column by B + for j in range(len(B[0])): + + # iterating by rows of B + for k in range(len(B)): + result[i][j] += A[i][k] * B[k][j] + +for r in result: + print(r) From 6581e3c835447e6b3a948d7521799f184151497b Mon Sep 17 00:00:00 2001 From: ATUL Date: Fri, 1 Oct 2021 22:57:15 +0530 Subject: [PATCH 6/9] palindrome --- palindrome.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 palindrome.py diff --git a/palindrome.py b/palindrome.py new file mode 100644 index 0000000..9a13893 --- /dev/null +++ b/palindrome.py @@ -0,0 +1,14 @@ +# function which return reverse of a string + +def isPalindrome(s): + return s == s[::-1] + + +# Driver code +s = "malayalam" +ans = isPalindrome(s) + +if ans: + print("Yes") +else: + print("No") From 40ab68bb157d15a1de3602b984b29e478347b71e Mon Sep 17 00:00:00 2001 From: ATUL Date: Fri, 1 Oct 2021 23:00:21 +0530 Subject: [PATCH 7/9] reverse --- reverse.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 reverse.cpp diff --git a/reverse.cpp b/reverse.cpp new file mode 100644 index 0000000..77772e1 --- /dev/null +++ b/reverse.cpp @@ -0,0 +1,15 @@ +#include +using namespace std; +int main() +{ +int n, reverse=0, rem; +cout<<"Enter a number: "; +cin>>n; + while(n!=0) + { + rem=n%10; + reverse=reverse*10+rem; + n/=10; + } + cout<<"Reversed Number: "< Date: Fri, 1 Oct 2021 23:04:11 +0530 Subject: [PATCH 8/9] add --- add.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 add.c diff --git a/add.c b/add.c new file mode 100644 index 0000000..8d2abe1 --- /dev/null +++ b/add.c @@ -0,0 +1,14 @@ +#include +int main() { + + int number1, number2, sum; + + printf("Enter two integers: "); + scanf("%d %d", &number1, &number2); + + // calculating sum + sum = number1 + number2; + + printf("%d + %d = %d", number1, number2, sum); + return 0; +} \ No newline at end of file From c5b599016fc5d727a3d199bb53bad2b13c763a59 Mon Sep 17 00:00:00 2001 From: ATUL Date: Fri, 1 Oct 2021 23:07:28 +0530 Subject: [PATCH 9/9] helllo --- hello.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 hello.txt diff --git a/hello.txt b/hello.txt new file mode 100644 index 0000000..e83bcc9 --- /dev/null +++ b/hello.txt @@ -0,0 +1 @@ +Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. \ No newline at end of file