Skip to content

Instantly share code, notes, and snippets.

View shaunlgs's full-sized avatar
🌴
On vacation

Shaun Ling shaunlgs

🌴
On vacation
View GitHub Profile
@shaunlgs
shaunlgs / charToIntArray.c
Last active May 26, 2023 11:23
Convert char array into int array in C.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int intArray[255];
static char charArray[255] = "5 2 -3 4 0 9";
static int numInt = 0;
void charToIntArray() {
char *p;
#include <iostream>
#include <conio.h>
using namespace std;
class Node {
public:
double data;
Node* next;
};
@shaunlgs
shaunlgs / insertionSort.cpp
Created October 9, 2016 03:29
This code is from Data Structure class UTM SPACE 2016
#include <stdio.h>
#include <conio.h>
void isihan_selitan(int, int []);
int main()
{
int i, saiz=10, susun[10] = {24,64,10,5,6,31,15,20,56,34};
printf("\n Data belum terisih :\n");
#include <iostream>
#include <conio.h>
using namespace std;
void BubbleSort(int data[], int listSize)
{
int pass, tempValue;
for(pass = 1; pass < listSize; pass++)
{
for(int x=0; x < listSize - pass; x++)
#include <stdio.h>
#include <conio.h>
void BubbleSort(int [], int);
int main()
{
int i,saiz=10, susun[10] = {24,64,10,5,6,31,15,20,56,34};
printf("\n Data belum terisih :\n");
// Program 2.14
#include <iostream>
using namespace std;
int bil = 0;
class UJI
{
private:
int nilai;
public:
n = int(input())
raw = input().split(" ")
decisions = []
# decide first move
for i in range(1):
# gym no, contest no
if raw[i] == "0":
@shaunlgs
shaunlgs / dijkstra.cpp
Created June 19, 2016 02:38
Dijkstra algorithm to find shortest path for graph
// Inspiration from http://www.geeksforgeeks.org/greedy-algorithms-set-6-dijkstras-shortest-path-algorithm/
// Most of this code by me, adjacency matrix from above
#include <iostream>
#include <string>
using namespace std;
#define numOfVertices 9
@shaunlgs
shaunlgs / euclid.php
Last active March 30, 2016 18:02
LCM method (using GCD through Euclid) to find the smallest number that can be divided with number 1 to 20
<?php
/*
* function gcd()
*
* returns greatest common divisor
* between two numbers
* tested against gmp_gcd()
* credit: http://php.net/manual/en/function.gmp-gcd.php#86931
*/
function gcd($a, $b)
@shaunlgs
shaunlgs / bruteForce.php
Created December 5, 2015 13:59
Brute force method to find the smallest number that can be divided with number 1 to 10
<?php
$number = 1;
while(true)
{
$i = 0;
for($i=1; $i < 11; $i++)
{
if($number % $i != 0)
{
break;