Skip to content

Instantly share code, notes, and snippets.

View xnorcode's full-sized avatar
🛠️
building stuff

Andreas Ioannou xnorcode

🛠️
building stuff
View GitHub Profile
@xnorcode
xnorcode / LinkedListNodeClass.java
Last active May 3, 2018 21:10
Linked List Node Class
public class LinkedList<T> {
// Reference to the head node
Node head;
// node class
class Node {
// Node data
T data;
@xnorcode
xnorcode / LinkedListPrintAll.java
Last active May 3, 2018 21:10
Linked List Print All Nodes
public class LinkedList<T> {
// Reference to the head node
Node head;
public void printAll(){
// get reference to the head node
Node next = head;
@xnorcode
xnorcode / LinkedListAddToHead.java
Last active May 3, 2018 19:08
Linked List Add Node To Head
public class LinkedList<T> {
// Reference to the head node
Node head;
public void addToHead(T data){
// create the new Node and add head as its next
Node newNode = new Node(data, head);
@xnorcode
xnorcode / LinkedListAddToTail.java
Created May 3, 2018 15:37
Linked List Add Node To Tail
public class LinkedList<T> {
// Reference to the head node
Node head;
public void addToTail(T data){
// create new node
Node newNode = new Node(data, null);
@xnorcode
xnorcode / LinkedListAddAfter.java
Created May 3, 2018 16:38
Linked List Add Node After Another Node
public class LinkedList<T> {
// Reference to the head node
Node head;
public void addAfter(T data, T target){
// create new node
Node newNode = new Node(data, null);
@xnorcode
xnorcode / LinkedListRemoveNode.java
Created May 3, 2018 17:01
Linked List Remove Node
public class LinkedList<T> {
// Reference to the head node
Node head;
public void removeNode(T data){
// check if list empty
if(head == null) return;
@xnorcode
xnorcode / LinkedListRemoveDuplicates.java
Created May 3, 2018 18:58
Linked List Remove Duplicate Nodes
public class LinkedList<T> {
// Reference to the head node
Node head;
public void removeDuplicates(){
// check if list empty
if(head == null) return;
@xnorcode
xnorcode / LinkedListHasCycle.java
Created May 3, 2018 19:23
Linked List Check For Cycle
public class LinkedList<T> {
// Reference to the head node
Node head;
public boolean hasCycle(){
// check if list empty
if(head == null) return false;
@xnorcode
xnorcode / SimpleArray.java
Last active August 29, 2018 16:15
Simple Array Manipulation in Java
...
// Method 1
// create array of already known numbers
int[] numbers = {10,2,5,8,37,6};
// printing all numbers
for(int i = 0; i < numbers.length; i++){
System.out.println(numbers[i]);
@xnorcode
xnorcode / Anagrams.java
Last active August 29, 2018 16:15
Anagrams Check with Array
...
static boolean isAnagram(String str1, String str2){
// not the same size its not anagram
if(str1.length() != str2.length()) return false;
// integer array of 26 for each letter of English alphabet
int[] letters = new int[26];