Skip to content
This repository was archived by the owner on Aug 20, 2024. It is now read-only.

Sorted out the missing file warning and added code for Pell Numbers #132

Open
wants to merge 2 commits into
base: master
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
109 changes: 67 additions & 42 deletions C++/Sorting algo/quicksort.cpp
Original file line number Diff line number Diff line change
@@ -1,42 +1,67 @@
// A utility function to swap two elements
void swap(int* a, int* b)
{
int t = *a;
*a = *b;
*b = t;
}
int partition (int arr[], int low, int high)
{
int pivot = arr[high]; // pivot
int i = (low - 1); // Index of smaller element

for (int j = low; j <= high - 1; j++)
{
// If current element is smaller than the pivot
if (arr[j] < pivot)
{
i++; // increment index of smaller element
swap(&arr[i], &arr[j]);
}
}
swap(&arr[i + 1], &arr[high]);
return (i + 1);
}

void quickSort(int arr[], int low, int high)
{
if (low < high)
{
int pi = partition(arr, low, high);
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}
/* Function to print an array */
void printArray(int arr[], int size)
{
int i;
for (i = 0; i < size; i++)
cout << arr[i] << " ";
cout << endl;
}
#include <iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<unordered_map>
using namespace std;



int partition (int arr[], int low, int high)
{
int pivot = arr[high]; // pivot
int i = (low - 1); // Index of smaller element

for (int j = low; j <= high- 1; j++)
{
// If current element is smaller than or
// equal to pivot
if (arr[j] <= pivot)
{
i++; // increment index of smaller element
swap(arr[i], arr[j]);
}
}
swap(arr[i + 1], arr[high]);
return (i + 1);
}


void quickSort(int arr[], int low, int high)
{
if (low < high)
{
/* pi is partitioning index, arr[p] is now
at right place */
int pi = partition(arr, low, high);

// Separately sort elements before
// partition and after partition
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}


void printArray(int arr[], int size)
{
int i;
for (i=0; i < size; i++)
cout<<arr[i]<<" ";
cout<<endl;
}

int main()
{
int arr[] = {10, 7, 8, 9, 1, 5};
int n = sizeof(arr)/sizeof(arr[0]);

cout<<"Unsorted array:"<<"\n";
printArray(arr, n);
quickSort(arr, 0, n-1);
cout<<"Sorted array:"<<"\n";
printArray(arr, n);
return 0;
}
21 changes: 21 additions & 0 deletions Java/pell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.io.*;
import java.util.*;

class pell{

public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
//User input of the number of pell numbers
int n = sc.nextInt();
int a=1,b=0,c,i;
System.out.println("First "+n+" Pell numbers are: ");
for(i=1; i<=n; i++)
{
c= a + 2*b;
System.out.print(c+" ");
a = b;
b = c;
}
}
}