Skip to content

Instantly share code, notes, and snippets.

View paullewallencom's full-sized avatar
🎯
Focusing

Paul Lewallen paullewallencom

🎯
Focusing
View GitHub Profile
@paullewallencom
paullewallencom / AvlTree.h
Created July 31, 2018 20:17
AVL tree (Adelson-Velskii & Landis)
#ifndef AVL_TREE_H
#define AVL_TREE_H
#include "dsexceptions.h"
#include <algorithm>
#include <iostream>
using namespace std;
template <typename Comparable>
class AvlTree
@paullewallencom
paullewallencom / BinarySearchTree.h
Created July 31, 2018 20:10
Binary Search Tree
#ifndef BINARY_SEARCH_TREE_H
#define BINARY_SEARCH_TREE_H
#include "dsexceptions.h"
#include <algorithm>
using namespace std;
template <typename Comparable>
class BinarySearchTree
{
#ifndef LIST_H
#define LIST_H
#include <algorithm>
using namespace std;
template <typename Object>
class List
{
private:
#ifndef VECTOR_H
#define VECTOR_H
#include <algorithm>
#include <iostream>
#include <stdexcept>
#include "dsexceptions.h"
template <typename Object>
class Vector
@paullewallencom
paullewallencom / IntCell.cpp
Last active July 31, 2018 18:37
C++ Simulates Int Memory
#include "IntCell.h"
IntCell::IntCell( int initialValue ) : storedValue{ initialValue }
{
}
int IntCell::read( ) const
{
return storedValue;
}
@paullewallencom
paullewallencom / ListInsertionSort.cpp
Created July 27, 2018 04:13
C++ List Insertion Sort
struct node heada, headb;
link t, u, x, a = &heada, b;
for ( i = 0, t = a; i < N; i++ )
{
t->next = malloc( sizeof *t );
t = t->next; t->next = NULL;
t->item = rand() % 1000;
}
b = &headb; b->next = NULL;
@paullewallencom
paullewallencom / BinarySearch.cpp
Last active July 31, 2018 18:46
C++ Binary Search
#include <iostream>
#include <vector>
using namespace std;
const int NOT_FOUND = -1;
template <typename Comparable>
int binarySearch( const vector<Comparable> & a, const Comparable & x )
{
int low = 0, high = a.size( ) - 1;
@paullewallencom
paullewallencom / Sequential.cpp
Last active July 27, 2018 00:34
C++ Sequential Search
int search( int a[], int v, int l, int r )
{
int i;
for ( i = l; i <= r; i++ )
if ( v == a[ i ] ) return i;
return -1;
}
@paullewallencom
paullewallencom / WeightedQuickUnion.cpp
Last active July 27, 2018 00:34
C++ Weighted Quick-Union
#include <stdio.h>
#define N 10000
main()
{
int i, j, p, q, id[ N ], sz[ N ];
for ( i = 0; i < N; i++ )
{
id[ i ] = i; sz[ i ] = 1;
}
@paullewallencom
paullewallencom / QuickFind.cpp
Last active July 27, 2018 00:33
C++ Quick-Find Algorithm
#include <stdio.h>
#define N 10000
main()
{
int i, p, q, t, id[ N ];
for ( i = 0; i < N; i++ ) id[ i ] = i;
while ( scanf( "%d %d\n", &p, &q ) == 2 )
{