Skip to content

Instantly share code, notes, and snippets.

View arunenigma's full-sized avatar

Shan arunenigma

  • Silicon Valley
View GitHub Profile
@arunenigma
arunenigma / project_euler_7.py
Created March 19, 2013 02:40
Project Euler Problem 7: Solution using generators!
def gen_primes():
D = {}
q = 2
while True:
if q not in D:
yield q
D[q * q] = [q]
else:
for p in D[q]:
D.setdefault(p + q, []).append(p)
@arunenigma
arunenigma / this.cpp
Created March 17, 2013 23:19
this pointer in C++
// C++ this pointer
#include <iostream>
using namespace std;
class MyClass {
int data;
public:
MyClass() {
data = 100;
}
@arunenigma
arunenigma / linked_list_using_classes.cpp
Created March 17, 2013 20:22
Linkedlist implementation using Classes in C++
// Linkedlist implementation using Classes in C++
#include <iostream>
using namespace std;
class Node {
public:
int data;
Node* next;
};
class LinkedList{
@arunenigma
arunenigma / reverse_linked_list.cpp
Created March 17, 2013 19:04
Linked List implementation and reversing it using structures in C++
// Simple Linked List Implementation in C++
#include <iostream>
using namespace std;
void insert(); // function prototype
void display(); // function prototype
void reverseList(); // function prototype
struct node {
@arunenigma
arunenigma / linked_list.cpp
Created March 14, 2013 16:55
Simple Linked List Implementation in C++
// Simple Linked List Implementation in C++
#include <iostream>
using namespace std;
void insert(); // function prototype
void display(); // function prototype
struct node {
int data;
@arunenigma
arunenigma / struct_with_pointers.cpp
Created March 14, 2013 00:39
struct with pointers " understanding -> " C++
// struct with pointers C++
#include <iostream>
using namespace std;
struct Person {
string name;
int age;
string sex;
};
int main() {
@arunenigma
arunenigma / struct.cpp
Last active December 14, 2015 22:19
struct example in c++
#include <iostream>
using namespace std;
struct Person {
string name; // name, age and sex are all public by default compared to class where its private by default
int age;
string sex;
void printDetails();
};
void Person::printDetails() {
@arunenigma
arunenigma / array_sum_pointers.cpp
Created March 13, 2013 01:31
Array Looping and Sum of elements (Using Pointers)
#include <iostream>
using namespace std;
double sum(double* a, int size) {
double total = 0;
double *p = a;
for (int i = 0; i < size; i++) {
total = total + *p;
p++;
}
@arunenigma
arunenigma / array_sum.cpp
Created March 11, 2013 19:50
Array Looping and Sum of an array (Normal Method)
#include<iostream>
using namespace std;
int sum(int a[], int size){
int total = 0;
for (int i = 0; i < size; i ++) {
total = total + a[i];
}
return total;
}
@arunenigma
arunenigma / pointer_ex_1.cpp
Created March 11, 2013 15:07
Pointer Example 1 C++
// pointer example 1
#include <iostream>
using namespace std;
int main() {
double chase = 0;
double discover = 50000;
double* balance = &chase; // balance is a pointer to chase account
*balance = 1000; // Initial deposit
*balance = *balance - 100; // withdraw 100$