#include <iostream>
using namespace std;
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
int L[n1], R[n2];
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
i = 0;
j = 0;
k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
while (
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
int L[n1], R[n2];
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1 + j];
i = 0;
j = 0;
k = l;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
arr[k] = L[i];
i++;
}
else {
arr[k] = R[j];
j++;
}
k++;
}
#include <iostream>
using namespace std;
void merge(int* arr, int low, int mid, int high)
{
int* temp = new int[high - low + 1];
int i = low, j = mid + 1;
int k = 0;
while(i <= mid && j <= high)
{
if(arr[i] <= arr[j])
temp[k++] = arr[i++];
else
temp[k++] = arr[j++];
}
while(i <= mid)
temp[k++] = arr[i++];
while(j <= high)
temp[k++] = arr[j++];
for(i = low, k = 0; i <= high; i++, k++)
arr[i] = temp[k];
delete[] temp;
}
void mergeSort(int* arr, int low, int high)
{
if(low < high)
{
int mid = (low + high
public class MergeSort {
public static void main(String[] args) {
int[] arr = { 5, 1, 6, 2, 3, 4 };
mergeSort(arr);
for(int i = 0; i < arr.length; i++) {
System.out.print(arr[i]);
}
}
public static void mergeSort(int[] arr) {
int size = arr.length;
if(size < 2) {
return;
}
int mid = size / 2;
int leftSize = mid;
int rightSize = size - mid;
int[] left = new int[leftSize];
int[] right = new int[rightSize];
for(int i = 0; i < mid; i++) {
left[i] = arr[i];
}
for(int i = mid; i < size; i++) {
right[i - mid] = arr[i];
}
mergeSort(left);
mergeSort(right);
merge(left
#include <stdio.h>
#include <iostream>
using namespace std;
void merge(int *array, int l, int m, int r)
{
int i, j, k, nl, nr;
//size of left and right sub-arrays
nl = m-l+1; nr = r-m;
int larr[nl], rarr[nr];
//fill left and right sub-arrays
for(i = 0; i<nl; i++)
larr[i] = array[l+i];
for(j = 0; j<nr; j++)
rarr[j] = array[m+1+j];
i = 0; j = 0; k = l;
//marge temp arrays to real array
while(i < nl && j<nr)
{
if(larr[i] <= rarr[j])
{
array[k] = larr[i];
i++;
}
else
function isPrime(num) {
if (num === 1) {
return false;
} else if (num === 2) {
return true;
} else {
for (var i = 2; i < num; i++) {
if (num % i === 0) {
return false;
}
}
return true;
}
}
public class MergeSort {
private int[] array;
private int[] tempMergArr;
private int length;
public static void main(String a[]){
int[] inputArr = {45,23,11,89,77,98,4,28,65,43};
MergeSort mms = new MergeSort();
mms.sort(inputArr);
for(int i:inputArr){
System.out.print(i);
System.out.print(" ");
}
}
public void sort(int inputArr[]) {
this.array = inputArr;
this.length = inputArr.length;
this.tempMergArr = new int[length];
doMergeSort(0, length - 1);
}
private void doMergeSort(int lowerIndex, int higherIndex) {
if (lowerIndex < higherIndex) {
int middle = lowerIndex + (higherIndex - lowerIndex) / 2;
// Below step sorts the
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void merge_sort(int *, int, int);
void merge(int *, int, int, int);
void print(int *, int);
void merge_sort(int *arr, int l, int r) {
if (l < r) {
int m = l+(r-l)/2;
merge_sort(arr, l, m);
merge_sort(arr, m+1, r);
merge(arr, l, m, r);
}
}
void merge(int *arr, int l, int m, int r) {
vector<int> L;
vector<int> R;
int i, j, k;
for (i = l; i <= m; i++) {
L.push_back(arr[i]);
}
for (i = m+1; i <= r; i++) {
R.push_back(arr[i]);
<form method="POST" action="register.php">
<input type="hidden" name="register" value="true">
<input type="text" name="username" value="<?php if (isset($_SESSION['username'])) echo $_SESSION['username'] ?>" placeholder="username">
<input type="password" name="password" value="" placeholder="password">
<input type="password" name="confirm_password" value="" placeholder="confirm password">
<input type="submit" name="register" value="Register">
</form>
class MergeSort
{
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
int L[] = new int [n1];
int R[] = new int [n2];
/*Copy data to temp arrays*/
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays */
// Initial indexes of first and second subarr
#include <iostream>
#include <vector>
#define THRESHOLD 10
using namespace std;
void printArray(vector<int> A){
for (int i : A)
cout << i << " ";
cout << endl;
}
vector<int> merge(vector<int> left, vector<int> right){
int i = 0;
int j = 0;
vector<int> res;
while (i < left.size() && j < right.size()){
if (left[i] < right[j]){
res.push_back(left[i]);
i++;
}else{
res.push_back(right[j]);
j++;
}
}
while (i < left.size()){
res.push_back(left[i]);
i++;
}
while (j < right.size()){
res.push_back(right[j]);
j++;
}
return res
// C++ program to implement Merge Sort algorithm
#include <bits/stdc++.h>
using namespace std;
// A function to merge the two half into a sorted data.
void Merge(int *a, int low, int high, int mid)
{
// We have low to mid and mid+1 to high already sorted.
int i, j, k, temp[high-low+1];
i = low;
k = 0;
j = mid + 1;
// Merge the two parts into temp[].
while (i <= mid && j <= high)
{
if (a[i] < a[j])
{
temp[k] = a[i];
k++;
i++;
}
else
{
temp[k] = a[j];
k++;
j++;
}
}
// Insert all the remaining
int[] arr = {10, 2, 20, 1, 3, 100, 300, 4};
for(int i = 0; i < arr.length; i++)
{
for(int j = i; j < arr.length; j++)
{
if(arr[i] > arr[j])
{
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
for(int i = 0; i < arr.length; i++)
System.out.println(arr[i]);
<div id="register">
<div class="container">
<form action="/signup" method="post">
<h2>Register</h2>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter email">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Password">
</div>
<button type="submit" class="btn btn-primary">Register</button>
</form>
</div>
</div>
<div>
<h3>Login</h3>
<form [formGroup]="loginForm" (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="username">Username</label>
<input type="text" formControlName="username" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.username.errors }" />
<div *ngIf="submitted && f.username.errors" class="invalid-feedback">
<div *ngIf="f.username.errors.required">Username is required</div>
</div>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" formControlName="password" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.password.errors }" />
<div *ngIf="submitted && f.password.errors" class="invalid-feedback
#include <iostream>
class mergeSort
{
private:
int *arr;
int size;
public:
mergeSort(int *arr, int size);
void sort();
void print();
void merge(int l, int m, int r);
};
mergeSort::mergeSort(int *arr, int size)
{
this->arr = arr;
this->size = size;
}
void mergeSort::sort()
{
mergeSort::merge(0, size/2, size-1);
}
void mergeSort::merge(int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
int L[n1], R[n2];
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0;
public class MergeSort {
public static void mergeSort(int[] array) {
if (array.length > 1) {
int[] left = leftHalf(array);
int[] right = rightHalf(array);
mergeSort(left);
mergeSort(right);
merge(array, left, right);
}
}
public static int[] leftHalf(int[] array) {
int size1 = array.length / 2;
int[] left = new int[size1];
for (int i = 0; i < size1; i++) {
left[i] = array[i];
}
return left;
}
public static int[] rightHalf(int[] array) {
int size1 = array.length / 2;
int size2 = array.length - size1;
int[] right = new int[size2];
for (int i = 0; i < size2; i++) {
right[i] = array[i + size1];
}
#include <iostream>
using namespace std;
int main()
{
int number, i;
bool isPrime = true;
cout << "Enter a positive integer: ";
cin >> number;
for(i = 2; i <= number / 2; ++i)
{
if(number % i == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
cout << "This is a prime number";
else
cout << "This is not a prime number";
return 0;
}
public class Main {
public static void main(String[] args) {
int[] a = { 1, 2, 3, 4, 5, 6 };
int[] b = { 2, 3, 4, 7, 8 };
int n = a.length + b.length;
int[] c = new int[n];
int i = 0;
int j = 0;
int k = 0;
while (i < a.length && j < b.length) {
if (a[i] < b[j]) {
c[k] = a[i];
i++;
} else {
c[k] = b[j];
j++;
}
k++;
}
while (i < a.length) {
c[k] = a[i];
i++;
k++;
}
while (j < b.length) {
c[k] = b[j];
j++;
k++;
}
for (int x = 0
#include <iostream>
#include <vector>
using namespace std;
void mergeWithoutRepetition(vector<int>& v, int start, int middle, int end) {
vector<int> left(v.begin() + start, v.begin() + middle + 1);
vector<int> right(v.begin() + middle + 1, v.begin() + end + 1);
int i = 0, j = 0, k = start;
while(i < left.size() && j < right.size()) {
if(left[i] <= right[j]) {
v[k++] = left[i++];
} else {
v[k++] = right[j++];
}
}
while(i < left.size()) {
v[k++] = left[i++];
}
while(j < right.size()) {
v[k++] = right[j++];
}
}
import java.util.Arrays;
public class InPlaceMergeSort {
public static void main(String args[]){
int arr[] = {2,3,4,5,1};
int n = arr.length;
System.out.println("Given Array");
System.out.println(Arrays.toString(arr));
sort(arr, 0, n-1);
System.out.println("\nSorted array");
System.out.println(Arrays.toString(arr));
}
public static void sort(int arr[], int l, int r){
if (l < r)
{
int m = (l+r)/2;
sort(arr, l, m);
sort(arr , m+1, r);
merge(arr, l, m, r);
}
}
static void merge(int arr[], int l, int m, int r){
int i = 0;
int j = 0;
int k = l;
def printPrimes(n):
Primes = [True] * (n+1)
Primes[0] = Primes[1] = False
for i in range(2, n+1):
for j in range(i*i, n+1, i):
Primes[j] = False
for i in range(0, n+1):
if(Primes[i]):
print(i)
printPrimes(100)
def is_prime(n):
for i in range(2, n):
if n % i == 0:
return False
return True
<?php
if (isset($_POST['submit'])) {
require("connection.php");
$email = $_POST['email'];
$password = $_POST['password'];
$re_password = $_POST['re-password'];
$salt = "48@!alsd";
$hash_password = hash_hmac('sha256', $password, $salt);
if ($password == $re_password) {
$sql = "INSERT INTO user_accounts (email, password) VALUES ('$email', '$hash_password')";
$conn->query($sql);
header("Location: login.php");
} else {
echo "Password does not match";
}
$conn->close();
}
?>
#include <iostream>
#include<time.h>
#include <cstdlib>
#include <pthread.h>
#include <fstream>
#include <chrono>
using namespace std;
struct thread_data {
int start;
int end;
};
void *calculatePrimes(void *threadarg) {
// extract the struct data from the void pointer
struct thread_data *my_data;
my_data = (struct thread_data *) threadarg;
// get the start and end numbers from the parameter
int start = my_data->start;
int end = my_data->end;
// this is where the primes will be displayed
ofstream output;
output.open("output.txt", ios::app);
// calculate all the primes within the range
for(int i = start; i <= end; i++) {
int flag = 0;
for (int j = 2; j <= i/2; j++) {
if(i
#include <iostream>
using namespace std;
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
int L[n1], R[n2];
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1 + j];
i = 0;
j = 0;
k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
while (i < n1)
{
public class MergeSort {
private int[] numbers;
private int[] helper;
private int number;
public void sort(int[] values) {
this.numbers = values;
number = values.length;
this.helper = new int[number];
mergesort(0, number - 1);
}
private void mergesort(int low, int high) {
// check if low is smaller then high, if not then the array is sorted
if (low < high) {
// Get the index of the element which is in the middle
int middle = low + (high - low) / 2;
// Sort the left side of the array
mergesort(low, middle);
// Sort the right side of the array
mergesort(middle + 1, high);
// Combine them both
merge(low, middle, high);
}
}
private void merge(int low, int middle, int high) {
// Copy both parts into the helper array
for (int i = low
#include <iostream>
using namespace std;
void merge(int a[], int low, int mid, int high)
{
int i = low;
int j = mid + 1;
int k = low;
int temp[20];
while(i <= mid && j <= high)
{
if(a[i] <= a[j])
{
temp[k] = a[i];
k++;
i++;
}
else
{
temp[k] = a[j];
k++;
j++;
}
}
while(i <= mid)
{
temp[k] = a[i];
k++;
i++;
}
while(j <= high)
{
temp[k] = a[j];
k++;
j++;
}
for(i = low; i < k
public static void merge(int[] arr, int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
/* create temp arrays */
int[] L= new int[n1];
int[] R= new int[n2];
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays back into arr[l..r]*/
i = 0; // Initial index of first subarray
j = 0; // Initial index of second subarray
k = l; // Initial index of merged subarray
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
public class MergeSort {
public static void main(String[] args) {
int[] data = {5, 2, 4, 7, 1, 3, 2, 6};
System.out.println("Before: " + Arrays.toString(data));
mergeSort(data);
System.out.println("After: " + Arrays.toString(data));
}
public static void mergeSort(int[] data) {
if (data.length > 1) {
int mid = data.length / 2;
int[] leftData = Arrays.copyOfRange(data, 0, mid);
int[] rightData = Arrays.copyOfRange(data, mid, data.length);
mergeSort(leftData);
mergeSort(rightData);
merge(data, leftData, rightData);
}
}
public static void merge(int[] data, int[] leftData, int[] rightData) {
int i = 0;
int li = 0;
int ri = 0;
while
public static void main(String[] args) {
int[] nums = {0, 1, 2, 3, 4, 5, 6};
mergeSort(nums, 0, nums.length - 1);
System.out.println(Arrays.toString(nums));
}
private static void mergeSort(int[] nums, int left, int right) {
if (left < right) {
int mid = (left + right) / 2;
mergeSort(nums, left, mid);
mergeSort(nums, mid + 1, right);
merge(nums, left, mid, right);
}
}
private static void merge(int[] nums, int left, int mid, int right) {
while (left <= mid && mid + 1 <= right) {
if (nums[left] <= nums[mid + 1]) {
left++;
} else {
int temp = nums[mid + 1];
for (int i = mid + 1; i > left; i--)
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
int L[n1], R[n2];
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
i = 0;
j = 0;
k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
public class MergeSort {
public static void main(String[] args) {
int arr[] = {12, 11, 13, 5, 6, 7};
System.out.println("Given Array");
printArray(arr);
MergeSort ob = new MergeSort();
ob.sort(arr, 0, arr.length-1);
System.out.println("\nSorted array");
printArray(arr);
}
void sort(int arr[], int l, int r) {
if (l < r) {
int m = (l+r)/2;
sort(arr, l, m);
sort(arr , m+1, r);
merge(arr, l, m, r);
}
}
void merge(int arr[], int l, int m, int r) {
int n1 = m - l + 1;
int n2 = r - m;
int L[] = new int [n1];
int R[] = new int [n2];
for
#include <iostream>
#include <thread>
using namespace std;
void checkPrime(int num){
bool isPrime = true;
int sqrtNum = (int) sqrt(num);
for(int i = 2; i <= sqrtNum; i++){
if(num % i == 0){
isPrime = false;
break;
}
}
if(isPrime){
cout << num << " is a prime number" << endl;
}else{
cout << num << " is not a prime number" << endl;
}
}
int main(){
int start, end;
cout << "Input start and end: ";
cin >> start >> end;
thread t1(checkPrime, start);
thread t2(checkPrime, end);
t1.join();
t2.join();
return 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form>
<input type="email" name="email" placeholder="Email" required>
<input type="password" name="password" placeholder="Password" required>
<input type="submit" value="Register">
</form>
</body>
</html>
#include <iostream>
using namespace std;
void merge(int *a, int n, int m) {
int i, j, k;
int *x = new int[n];
for(i = 0, j = m, k = 0; k < n; k++) {
x[k] = j == n ? a[i++]
: i == m ? a[j++]
: a[j] < a[i] ? a[j++]
: a[i++];
}
for(i = 0; i < n; i++) {
a[i] = x[i];
}
delete[] x;
}
void merge_sort(int *a, int n) {
if(n < 2)
return;
int m = n / 2;
merge_sort(a, m);
merge_sort(a + m, n - m);
merge(a, n, m);
}
int main() {
def is_prime(n):
if type(n) != int or n < 0:
print("Invalid Input")
return False
for i in range(2, n):
if n % i == 0:
return False
return True
print(is_prime(3))
public class MergeSort {
public static void sort(int[] a, int n) {
if (n < 2) {
return;
}
int mid = n / 2;
int[] l = new int[mid];
int[] r = new int[n - mid];
for (int i = 0; i < mid; i++) {
l[i] = a[i];
}
for (int i = mid; i < n; i++) {
r[i - mid] = a[i];
}
sort(l, mid);
sort(r, n - mid);
merge(a, l, r, mid, n - mid);
}
public static void merge(
int[] a, int[] l, int[] r, int left, int right) {
int i = 0, j = 0, k = 0;
while (i < left && j < right) {
if (l[i] <= r[j]) {
a
public class MergeSort {
public static void sort(int[] arr) {
sort(arr, 0, arr.length-1);
}
private static void sort(int[] arr, int low, int high) {
if (high <= low) {
return;
}
int mid = low + (high - low) / 2;
sort(arr, low, mid);
sort(arr, mid+1, high);
merge(arr, low, mid, high);
}
private static void merge(int[] arr, int low, int mid, int high) {
int i = low;
int j = mid+1;
while (i <= mid && j <= high) {
if (arr[i] <= arr[j]) {
i++;
} else {
int temp = arr[j];
System.arraycopy(arr, i, arr, i+1, j-i);
arr[i] = temp;
i++;
mid++;
j++;
}
public class MergeSort {
private int[] array;
private int[] tempMergArr;
private int length;
public static void main(String a[]){
int[] inputArr = {45,23,11,89,77,98,4,28,65,43};
MergeSort mms = new MergeSort();
mms.sort(inputArr);
for(int i:inputArr){
System.out.print(i);
System.out.print(" ");
}
}
public void sort(int inputArr[]) {
this.array = inputArr;
this.length = inputArr.length;
this.tempMergArr = new int[length];
doMergeSort(0, length - 1);
}
private void doMergeSort(int lowerIndex, int higherIndex) {
if (lowerIndex < higherIndex) {
int middle = lowerIndex + (higherIndex - lower
def isPrime(n):
if n==1:
return False
if n==2:
return True
if n%2==0 and n>2:
return False
i=3
while i*i<=n:
if n%i==0:
return False
i=i+2
return True
x=int(input('Enter From: '))
y=int(input('Enter To: '))
for num in range(x,y):
if isPrime(num):
print(num)
int a[100], n;
int main()
{
int i, j, k, mid, temp;
cout<<"enter the number of elements\n";
cin>>n;
cout<<"enter the elements\n";
for(i=0; i<n; i++)
{
cin>>a[i];
}
merge_sort(0, n-1);
cout<<"sorted array\n";
for(i=0; i<n; i++)
{
cout<<a[i]<<"\t";
}
return 0;
}
void merge_sort(int low, int high)
{
int mid;
if(low<high)
{
mid=(low+high)/2;
merge_sort(low, mid);
merge_sort(mid+1, high);
merge(low, mid, high);
}
}
void merge(int low, int mid, int high)
{
int h, i,
public class Solution {
public int[] mergeSort(int[] arr) {
// Write your solution here.
if(arr == null || arr.length <= 1){
return arr;
}
int[] helper = new int[arr.length];
mergeSort(arr, helper, 0, arr.length - 1);
return arr;
}
private void mergeSort(int[] arr, int[] helper, int left, int right){
if(left >= right){
return;
}
int mid = left + (right - left) / 2;
mergeSort(arr, helper, left, mid);
mergeSort(arr, helper, mid + 1, right);
merge(arr, helper, left, mid, right);
}
private void merge(int[] arr, int[] helper, int left, int mid, int right){
for(int i = left; i <= right; i++){
helper[i] = arr[i];
}
int leftIndex = left;
int
#include<iostream>
#include<cstdlib>
using namespace std;
void merge(int *,int, int , int );
void mergesort(int *a, int low, int high)
{
int mid;
if (low < high)
{
mid=(low+high)/2;
mergesort(a,low,mid);
mergesort(a,mid+1,high);
merge(a,low,high,mid);
}
return;
}
void merge(int *a, int low, int high, int mid)
{
int i, j, k, c[50];
i = low;
k = low;
j = mid + 1;
while (i <= mid && j <= high)
{
if (a[i] < a[j])
{
c[k] = a[i];
k++;
i++;
}
else
{
c[k] = a[j];