This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(int argc, char* argv[]) { | |
// Node struct | |
struct Node { | |
int data; | |
Node *next; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
// Note: I was a bit tired wrapping this up, so I could use a bit more code comments | |
// And I didn't clean up a few things to have "proper coding style", normally mixing | |
// variables beginning with capitals and what not | |
// Note2 (Wrotten after it was uploaded): it looks like I was dynamically adding nodes to the | |
// linked list wrong, they should be added at the head, not the tail. | |
// Also, I'll work on being consistent on my code style in next ones, I'll just leave things here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main(void) { | |
int *p = (int*)malloc(sizeof(int)*2); | |
*p = 4; | |
++p; | |
*p = 2; | |
printf("%d", p[-1]); /* Prints 4 */ | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ==== Basics ===== | |
#This is how you comment in Ruby! Think # is like a // | |
puts "Hello, World!" | |
#Equivalent to System.out.println("Hello, World!"); | |
print "Type something in: " | |
#Equivalent to System.out.print("Type something in: ")\ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
struct dynamicNode { | |
void* data; | |
int type; | |
dynamicNode* next; | |
}; | |
// I've uploaded this so I may self-reference it later |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
typedef struct Node{void*data;int type;struct Node*next;}dynamicNode;int main() | |
{dynamicNode*first=(dynamicNode*)malloc(sizeof(dynamicNode));first->next= | |
(dynamicNode*)malloc(sizeof(dynamicNode));int m=4;float q=4.5;first->data=(void | |
*)(&m);first->next->data=(void*)(&q);printf("%f\n",(*(int*)first->data+*(float* | |
)first->next->data));int*a=(int*)malloc(sizeof(int));float*b=(float*)malloc( | |
sizeof(float));first->next->next=(dynamicNode*)malloc(sizeof(dynamicNode)); | |
first->next->next->next=(dynamicNode*)malloc(sizeof(dynamicNode));first->next-> | |
next->data=(void*)a;first->next->next->next->data=(void*)b;*a=5;*b=22.4;printf( | |
"%f\n",(*(int*)first->next->next->data+*(float*)first->next->next->next->data)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdlib> | |
#include <cstdio> | |
#include <iostream> | |
// Last one is for cin.ignore() | |
using namespace std; | |
typedef enum binDigPlaces { | |
b1 = 0x01, | |
b2 = 0x02, | |
b3 = 0x04, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void pushSortedAdjNode(adjNode** listHead, int newID, int newDistance) { | |
adjNode* newNode = malloc(sizeof(adjNode)); | |
newNode->id = newID; | |
newNode->distance = newDistance; | |
if (*listHead == NULL || (*listHead)->distance >= newDistance) { | |
newNode->next = *listHead; | |
*listHead = newNode; | |
return; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Our class | |
class Matrix2by2 | |
# Initialize with a 2x2 list | |
def initialize(x, y) | |
if not (x.is_a? Array and y.is_a? Array) then | |
throw(:notArray) | |
end | |
if (x.length != 2 and y.length != 2) then | |
throw(:notEqual) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Vec < Array | |
def initialize(ary) | |
super(@vec = ary) | |
end | |
def *(scalar) | |
Vec.new ( | |
@vec.map { |element| |