Skip to content

sorted existing matrices and improved performance #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions C++/Algorithms/sorting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include<iostream>
using namespace std;
void selectionSort(int a[], int n) {
int i, j, min, temp;
for (i = 0; i < n - 1; i++) {
min = i;
for (j = i + 1; j < n; j++)
if (a[j] < a[min])
min = j;
temp = a[i];
a[i] = a[min];
a[min] = temp;
}
}
int main() {
int a[] = { 22, 91, 35, 78, 10, 8, 75, 99, 1, 67 };
int n = sizeof(a)/ sizeof(a[0]);
int i;
cout<<"Given array is:"<<endl;
for (i = 0; i < n; i++)
cout<< a[i] <<" ";
cout<<endl;
selectionSort(a, n);
printf("\nSorted array is: \n");
for (i = 0; i < n; i++)
cout<< a[i] <<" ";
return 0;
}
53 changes: 53 additions & 0 deletions Java/Algorithms/Divide-and-Conquer/Intergrity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Java program to calculate SHA-1 hash value

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class GFG {
public static String encryptThisString(String input)
{
try {
// getInstance() method is called with algorithm SHA-1
MessageDigest md = MessageDigest.getInstance("SHA-1");

// digest() method is called
// to calculate message digest of the input string
// returned as array of byte
byte[] messageDigest = md.digest(input.getBytes());

// Convert byte array into signum representation
BigInteger no = new BigInteger(1, messageDigest);

// Convert message digest into hex value
String hashtext = no.toString(16);

// Add preceding 0s to make it 32 bit
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}

// return the HashText
return hashtext;
}

// For specifying wrong message digest algorithms
catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}

// Driver code
public static void main(String args[]) throws
NoSuchAlgorithmException
{

System.out.println("HashCode Generated by SHA-1 for: ");

String s1 = "GeeksForGeeks";
System.out.println("\n" + s1 + " : " + encryptThisString(s1));

String s2 = "hello world";
System.out.println("\n" + s2 + " : " + encryptThisString(s2));
}
}