Skip to content

Instantly share code, notes, and snippets.

vecvector<int> removeDuplicates(vector<int> A)
{
int j = 0;
for(int i = 1; i < A.size()-1; i++)
{
if (A[i] != A[i-1])
{
swap(A[j],A[i]);
j++;
}
/*Program to multiply two arbitary precision arrays */
vector<int> Multiply (vector<int> num1, vector<int> num2)
{
// The result will be sum of size of 2 numbers + 1. setting it to 0 initially
vector result(num1.size()+num2.size()+1,0);
//Return early if either is empty
if(num1.empty() || num2.empty())
return result;
/*Program which takes an input array and an index and rearranges the array such that values less than the element come first,
elements equal follow and finally followed by elements greater than the index element*/
//Notes: This is just the quicksort algorithm where they have given the random value and there is just one step
This solution is the same as the precvious code: only just add a condition to increment the current index when the values match
struct morphParameters{
int shape;
int size;
int oper;
Mat* src;
Mat* res;
};
void morphology(Mat* src, Mat *result, int size)
{
int choice;
@raunaqbn
raunaqbn / smoothing.cpp
Created July 3, 2016 23:39
Smoothing OpenCV
#include <opencv2/imgproc/imgproc.hpp>
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
void countSort(int* arr,int size, int exp)
{
int output[size];
int count[10];
for(int i=0; i<size; i++)
count[(arr[i]/exp)%10]++;
for(int i=1; i<10; i++)
count[i] += count[i-1];
@raunaqbn
raunaqbn / heapsort.c
Created July 2, 2016 01:53
Heap Sort
//Heapify function is used to convert a tree rooted at node root into a max heap
void heapify (int* arr, int root, int size)
{
int pos = root;
// location of children
int left = 2*root + 1;
int right = 2*root + 2;
if (arr[root] < arr[left])
@raunaqbn
raunaqbn / quicksort.c
Last active July 16, 2016 03:36
Quick Sort
void swap(int& a, int& b)
{
int temp = a;
a = b;
b = temp;
}
void partition(int * arr, int left, int right)
{
int pivotValue = arr[right];
void mergeArrays(int * arr, int l, int m, int r)
{
// Compare element by element from arr[l:m] with arr[m:r] and accordingly move index within idividual arr
int lsize = m-l+1; // this will include the middle element
int rsize = r-m;
int L[lsize];R[rsize];
for(int i=0; i < lsize; i++)
L[i] = arr[l+i];
for(int i=0; i < rsize; i++)
R[i] = arr[m+j];
#include "chapter2.h"
void display_video(char **argv)
{
// CvCapture structure is used to store the information of the various properties of the
// avi and the create file capture returns a pointer of this type initialized to the beginning
// of the avi
CvCapture *pCapture = cvCreateFileCapture(argv[1]);
// Create a window to display the video frames