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 / ReverseStringWithArray.java
Last active August 29, 2018 16:14
Revesring a string with arrays
...
// convert String to array of chars
char[] s = str.toCharArray();
// get length of string
int n = s.length;
// get middle of string
int middle = n/2;
@xnorcode
xnorcode / ReverseStringWithStack.java
Last active August 29, 2018 16:14
Reversing a String using Stack in Java
...
// create a stack of characters
Stack<Character> st = new Stack<Character>();
// convert string to reverse into an array of characters
char[] arr = str.toCharArray();
// iterate chars array and push each char into the stack
for(char c : arr){
@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];
@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 / 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 / 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 / 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 / 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 / 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 / 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);