From ae7aba0b4483deff74b623fb229f43008aec0dd3 Mon Sep 17 00:00:00 2001 From: KylerSmith Date: Sun, 9 Jul 2017 16:29:00 -0700 Subject: [PATCH 1/4] File clean-up --- .DS_Store | Bin 8196 -> 8196 bytes .../DecimalToOctal.java | 0 CountChar.java => Misc/CountChar.java | 0 Dijkshtra.java => Misc/Dijkshtra.java | 0 Factorial.java => Misc/Factorial.java | 0 FindingPrimes.java => Misc/FindingPrimes.java | 0 ReverseString.java => Misc/ReverseString.java | 0 countwords.java => Misc/countwords.java | 0 ft.java => Misc/ft.java | 0 krishnamurthy.java => Misc/krishnamurthy.java | 0 .../removeDuplicateFromString.java | 0 data_structures/{ => Graphs}/Graphs.java | 0 bfs.java => data_structures/Graphs/bfs.java | 28 +++++++++--------- dfs.java => data_structures/Graphs/dfs.java | 0 .../{ => Lists}/CircleLinkedList.java | 0 .../{ => Lists}/DoublyLinkedList.java | 0 .../{ => Lists}/SinglyLinkedList.java | 0 .../{ => Queues}/PriorityQueues.java | 0 data_structures/{ => Queues}/Queues.java | 0 data_structures/{ => Stacks}/Stacks.java | 0 data_structures/{ => Trees}/AVLTree.java | 0 21 files changed, 14 insertions(+), 14 deletions(-) rename DecimalToOctal.java => Conversions/DecimalToOctal.java (100%) rename CountChar.java => Misc/CountChar.java (100%) rename Dijkshtra.java => Misc/Dijkshtra.java (100%) rename Factorial.java => Misc/Factorial.java (100%) rename FindingPrimes.java => Misc/FindingPrimes.java (100%) rename ReverseString.java => Misc/ReverseString.java (100%) rename countwords.java => Misc/countwords.java (100%) rename ft.java => Misc/ft.java (100%) rename krishnamurthy.java => Misc/krishnamurthy.java (100%) rename removeDuplicateFromString.java => Misc/removeDuplicateFromString.java (100%) rename data_structures/{ => Graphs}/Graphs.java (100%) rename bfs.java => data_structures/Graphs/bfs.java (85%) rename dfs.java => data_structures/Graphs/dfs.java (100%) rename data_structures/{ => Lists}/CircleLinkedList.java (100%) rename data_structures/{ => Lists}/DoublyLinkedList.java (100%) rename data_structures/{ => Lists}/SinglyLinkedList.java (100%) rename data_structures/{ => Queues}/PriorityQueues.java (100%) rename data_structures/{ => Queues}/Queues.java (100%) rename data_structures/{ => Stacks}/Stacks.java (100%) rename data_structures/{ => Trees}/AVLTree.java (100%) diff --git a/.DS_Store b/.DS_Store index f28585d78e4c824a62c4e8ee30d752891efb7b22..08cfaf755976285dd6706dd9a6835e8362d21b2b 100644 GIT binary patch delta 869 zcmbVK&ubG=5T4hjW~;{RCfPJp!O$SKG>4Q`1A@3o3mQcdni3KkZL^z~WN~-jc6Za7 z#+V#>5Kq^uA6Z&h;z2Nc_+sv&}T>Wb(TWSrXUE>upq=*(Qq>!k43{* zglnx9!^~Y;xslq|8vD)1ttYP?k-LcAQ1+5D?W_GC`-N|zt;oBEq!Nh^+La7dvFupv z8_S}pY1hmtH#2+s%vsMlFU$G-T!7jNSIbEq(*v^mD zg`S;k5>?F*OR*KA7m9s*8*3@OLa1eLgtXCvtQTi#4k{KRg93nI(S}ZROu@|HEh63>f($G} z0=tluy6{19PJ`F6!LjFV9@3^k>~*@CY4tK6c%q-!5Uy=OnFvlKSum3M%I@ literal 8196 zcmeHM-A)rh6h6a`Y(oSBCU9l;#>5LkAVdilQDFL7Yiu&g|~_&YAtr{Pb*zNR-;{8qpFFS*R@MrqTSS z@N=$1WlY~;umGOu4LNj7&Q1{3hP2HM!+>GHFkl!k3>XHk0s}a+xmY>pzItj}!+>Gn zzhr>-2OE`TQOmxPa_c}NQvk>b+?EA>#czu+q`N++w%8zP`R}Z`|uG+uhAgbnkDj^?H`IcxUb5&SCT9efLA}KYk6N4GGqYj_UVW_Nw}@&(#?{I5MGrFTdWIfjq&y3FHu-YYdE;ci z=@~H(tdDu@%C=6s(n6Ex(kTA}@45gR0eqjp%Dx^!NOj!vV50`0$m zNbaF!_&mbf`FKZORUUYV@vKP|8A0Z?o;Mm^o0&J-gN3ub+4~b4LmXN_c^FHK5jD`u zaLy;fK=db}&vPcpYBE=On%8ufNO6(b5kSS2D&uN2OPv32=YRjdQe!rQF$@?6E|&o@ zQLdCruzB`_Hfx@9Z5#Cvl?&_jm6Q-PG98DM={V&1ABO1LP-RR}%f6DhgYx%31Y}N2 QbN-V#|1UA~`$x|IpZ9>FN&o-= diff --git a/DecimalToOctal.java b/Conversions/DecimalToOctal.java similarity index 100% rename from DecimalToOctal.java rename to Conversions/DecimalToOctal.java diff --git a/CountChar.java b/Misc/CountChar.java similarity index 100% rename from CountChar.java rename to Misc/CountChar.java diff --git a/Dijkshtra.java b/Misc/Dijkshtra.java similarity index 100% rename from Dijkshtra.java rename to Misc/Dijkshtra.java diff --git a/Factorial.java b/Misc/Factorial.java similarity index 100% rename from Factorial.java rename to Misc/Factorial.java diff --git a/FindingPrimes.java b/Misc/FindingPrimes.java similarity index 100% rename from FindingPrimes.java rename to Misc/FindingPrimes.java diff --git a/ReverseString.java b/Misc/ReverseString.java similarity index 100% rename from ReverseString.java rename to Misc/ReverseString.java diff --git a/countwords.java b/Misc/countwords.java similarity index 100% rename from countwords.java rename to Misc/countwords.java diff --git a/ft.java b/Misc/ft.java similarity index 100% rename from ft.java rename to Misc/ft.java diff --git a/krishnamurthy.java b/Misc/krishnamurthy.java similarity index 100% rename from krishnamurthy.java rename to Misc/krishnamurthy.java diff --git a/removeDuplicateFromString.java b/Misc/removeDuplicateFromString.java similarity index 100% rename from removeDuplicateFromString.java rename to Misc/removeDuplicateFromString.java diff --git a/data_structures/Graphs.java b/data_structures/Graphs/Graphs.java similarity index 100% rename from data_structures/Graphs.java rename to data_structures/Graphs/Graphs.java diff --git a/bfs.java b/data_structures/Graphs/bfs.java similarity index 85% rename from bfs.java rename to data_structures/Graphs/bfs.java index 90ff4eca87ef..4f3bd62d339c 100644 --- a/bfs.java +++ b/data_structures/Graphs/bfs.java @@ -2,27 +2,27 @@ /** * Implementation of a Breadth First Search - * + * * @author Unknown * */ public class bfs{ - + /** - * The BFS implemented in code to use. - * - * @param a Structure to perform the search on + * The BFS implemented in code to use. + * + * @param a Structure to perform the search on a graph, adjacency matrix etc. * @param vertices The vertices to use * @param source The Source */ public static void bfsImplement(byte [][] a,int vertices,int source){ //passing adjacency matrix and no of vertices byte []b=new byte[vertices]; //flag container containing status of each vertices Arrays.fill(b,(byte)-1); //status initialization - /* code status + /* code status -1 = ready 0 = waiting 1 = processed */ - + Stack st = new Stack(vertices); //operational stack st.push(source); //assigning source while(!st.isEmpty()){ @@ -30,18 +30,18 @@ public static void bfsImplement(byte [][] a,int vertices,int source){ //passing System.out.println(st.peek()); int pop=st.peek(); b[pop]=(byte)1; //assigning processed status - st.pop(); //removing head of the queue + st.pop(); //removing head of the queue for(int i=0;i Date: Sun, 9 Jul 2017 17:11:57 -0700 Subject: [PATCH 2/4] Syntax fix --- data_structures/Stacks/Stacks.class | Bin 0 -> 993 bytes data_structures/Stacks/Stacks.java | 62 ++++++++++++++-------------- 2 files changed, 31 insertions(+), 31 deletions(-) create mode 100644 data_structures/Stacks/Stacks.class diff --git a/data_structures/Stacks/Stacks.class b/data_structures/Stacks/Stacks.class new file mode 100644 index 0000000000000000000000000000000000000000..260579a9d9d0f1ad6341f432d55d1663c37156c5 GIT binary patch literal 993 zcma)**-sNu6vltI&<-uNR5n*+aiO%83gTJ>2|_|r#iYgrOiTtGaiE*+RKt_cKKtym z&+t$ZNKA}N6g9>r?thE%+-Zc6^uasHIo~<=yWgF2&dlbY^{2oPV*%RfH0TQ8pO7XfAh6WeXWA zYvml%vGciF?5M$+AZIxjm2zF(LB)7Ynd+@6yX5@OrT^qg zitu(*rso!|c}F@HnQ}W?D3|W+Af%T|j+K>;=gUHCtM=2*C$35}9cig$W|N8*S8-=r zVH7keBa>*0)EIG+EAMBraIilDj!2wvaE-O`CjZdU;TK zT4MJ})FEDp_eR%HD*_bz#roXjI(`mtP_R%{4|Vdu>IR+}V~x60tf4}EEbLmZ3;kkO z@izM^7~*3UWYb?ofi2WnAz01r+CnPTt z1hrH(1hsCVow@D0Zc6F!OzL_rKgbJOc`3EMqLbJ3@`eF6N%EEn-Z9O4X83@~M{e_p j44=8n7w+?w2Yllp-+9Cj9`lnY{9=XQ(y0#7_i*ShC^XL& literal 0 HcmV?d00001 diff --git a/data_structures/Stacks/Stacks.java b/data_structures/Stacks/Stacks.java index 4e2b08545721..2158563173ba 100644 --- a/data_structures/Stacks/Stacks.java +++ b/data_structures/Stacks/Stacks.java @@ -3,13 +3,13 @@ /** * This class implements a Stack using two different implementations. * Stack is used with a regular array and Stack2 uses an ArrayList. - * + * * A stack is exactly what it sounds like. An element gets added to the top of * the stack and only the element on the top may be removed. This is an example * of an array implementation of a Stack. So an element can only be added/removed * from the end of the array. In theory stack have no fixed size, but with an * array implementation it does. - * + * * @author Unknown * */ @@ -23,7 +23,7 @@ class Stack{ /** * Constructor - * + * * @param size Size of the Stack */ public Stack(int size){ @@ -34,7 +34,7 @@ public Stack(int size){ /** * Adds an element to the top of the stack - * + * * @param value The element added */ public void push(int value){ @@ -42,13 +42,13 @@ public void push(int value){ top++; stackArray[top] = value; }else{ - System.out.prinln("The stack is full, can't insert value"); + System.out.println("The stack is full, can't insert value"); } } /** * Removes the top element of the stack and returns the value you've removed - * + * * @return value popped off the Stack */ public int pop(){ @@ -62,7 +62,7 @@ public int pop(){ /** * Returns the element at the top of the stack - * + * * @return element at the top of the stack */ public int peek(){ @@ -76,7 +76,7 @@ public int peek(){ /** * Returns true if the stack is empty - * + * * @return true if the stack is empty */ public boolean isEmpty(){ @@ -85,16 +85,16 @@ public boolean isEmpty(){ /** * Returns true if the stack is full - * + * * @return true if the stack is full */ public boolean isFull(){ return(top+1 == maxSize); } - + /** * Deletes everything in the Stack - * + * * Doesn't delete elements in the array * but if you call push method after calling * makeEmpty it will overwrite previous @@ -108,41 +108,41 @@ public void makeEmpty(){ //Doesn't delete elements in the array but if you call /** * This is an ArrayList Implementation of stack, Where size is not * a problem we can extend the stack as much as we want. - * + * * @author Unknown * */ class Stack2{ /** ArrayList representation of the stack */ ArrayList stackList; - + /** * Constructor */ Stack2(){ stackList=new ArrayList<>(); } - + /** * Adds value to the end of list which * is the top for stack - * + * * @param value value to be added */ void push(int value){ stackList.add(value); } - + /** * Pops last element of list which is indeed * the top for Stack - * + * * @return Element popped */ int pop(){ - + if(!isEmpty()){ // checks for an empty Stack - + int popValue=stackList.get(stackList.size()-1); stackList.remove(stackList.size()-1); //removes the poped element from the list return popValue; @@ -151,25 +151,25 @@ int pop(){ System.out.print("The stack is already empty "); return -1; } - + } - + /** * Checks for empty Stack - * + * * @return true if stack is empty */ boolean isEmpty(){ if(stackList.isEmpty()) return true; - + else return false; - + } - + /** * Top element of stack - * + * * @return top element of stack */ int peek(){ @@ -179,14 +179,14 @@ int peek(){ /** * This class implements the Stack and Stack2 created above - * + * * @author Unknown * */ public class Stacks{ /** * Main method - * + * * @param args Command line arguments */ public static void main(String args[]){ @@ -196,21 +196,21 @@ public static void main(String args[]){ myStack.push(8); myStack.push(2); myStack.push(9); - + System.out.println("*********************Stack Array Implementation*********************"); System.out.println(myStack.isEmpty()); //will print false System.out.println(myStack.isFull()); //will print true System.out.println(myStack.peek()); //will print 9 System.out.println(myStack.pop()); //will print 9 System.out.println(myStack.peek()); // will print 2 - + Stack2 myStack2 = new Stack2(); //Declare a stack of maximum size 4 //Populate the stack myStack2.push(5); myStack2.push(8); myStack2.push(2); myStack2.push(9); - + System.out.println("*********************Stack List Implementation*********************"); System.out.println(myStack2.isEmpty()); //will print false System.out.println(myStack2.peek()); //will print 9 From 96e89dbaac08cd2db4419fc9364823e81a7b6088 Mon Sep 17 00:00:00 2001 From: KylerSmith Date: Sun, 9 Jul 2017 17:12:59 -0700 Subject: [PATCH 3/4] Remove .class file --- data_structures/Stacks/Stacks.class | Bin 993 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 data_structures/Stacks/Stacks.class diff --git a/data_structures/Stacks/Stacks.class b/data_structures/Stacks/Stacks.class deleted file mode 100644 index 260579a9d9d0f1ad6341f432d55d1663c37156c5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 993 zcma)**-sNu6vltI&<-uNR5n*+aiO%83gTJ>2|_|r#iYgrOiTtGaiE*+RKt_cKKtym z&+t$ZNKA}N6g9>r?thE%+-Zc6^uasHIo~<=yWgF2&dlbY^{2oPV*%RfH0TQ8pO7XfAh6WeXWA zYvml%vGciF?5M$+AZIxjm2zF(LB)7Ynd+@6yX5@OrT^qg zitu(*rso!|c}F@HnQ}W?D3|W+Af%T|j+K>;=gUHCtM=2*C$35}9cig$W|N8*S8-=r zVH7keBa>*0)EIG+EAMBraIilDj!2wvaE-O`CjZdU;TK zT4MJ})FEDp_eR%HD*_bz#roXjI(`mtP_R%{4|Vdu>IR+}V~x60tf4}EEbLmZ3;kkO z@izM^7~*3UWYb?ofi2WnAz01r+CnPTt z1hrH(1hsCVow@D0Zc6F!OzL_rKgbJOc`3EMqLbJ3@`eF6N%EEn-Z9O4X83@~M{e_p j44=8n7w+?w2Yllp-+9Cj9`lnY{9=XQ(y0#7_i*ShC^XL& From 8dcd01ef5f310f509f9b3447b532f137112e2b85 Mon Sep 17 00:00:00 2001 From: KylerSmith Date: Mon, 10 Jul 2017 07:31:42 -0700 Subject: [PATCH 4/4] Added NodeStack.java, another stack implementation --- data_structures/Stacks/NodeStack.java | 183 ++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 data_structures/Stacks/NodeStack.java diff --git a/data_structures/Stacks/NodeStack.java b/data_structures/Stacks/NodeStack.java new file mode 100644 index 000000000000..c598bb8fcba1 --- /dev/null +++ b/data_structures/Stacks/NodeStack.java @@ -0,0 +1,183 @@ +/** +* Implementation of a stack using nodes. +* Unlimited size, no arraylist. +* +* @author Kyler Smith, 2017 +*/ + + +public class NodeStack { + + /** + * Entry point for the program. + */ + public static void main(String[] args) { + NodeStack Stack = new NodeStack(); + + Stack.push(3); + Stack.push(4); + Stack.push(5); + System.out.println("Testing :"); + Stack.print(); // prints : 5 4 3 + + Integer x = Stack.pop(); // x = 5 + Stack.push(1); + Stack.push(8); + Integer y = Stack.peek(); // y = 8 + System.out.println("Testing :"); + Stack.print(); // prints : 8 1 4 3 + + System.out.println("Testing :"); + System.out.println("x : " + x); + System.out.println("y : " + y); + } + + /** + * Information each node should contain. + * @value data : information of the value in the node + * @value head : the head of the stack + * @value next : the next value from this node + * @value previous : the last value from this node + * @value size : size of the stack + */ + private Item data; + private static NodeStack head; + private NodeStack next; + private NodeStack previous; + private static int size = 0; + + + /** + * Constructors for the NodeStack. + */ + public NodeStack() { + } + + private NodeStack(Item item) { + this.data = item; + } + + /** + * Put a value onto the stack. + * + * @param item : value to be put on the stack. + */ + public void push(Item item) { + + NodeStack newNs = new NodeStack(item); + + if(this.isEmpty()) { + NodeStack.setHead(new NodeStack<>(item)); + newNs.setNext(null); + newNs.setPrevious(null); + } else { + newNs.setPrevious(NodeStack.head); + NodeStack.head.setNext(newNs); + NodeStack.head = newNs; + } + + NodeStack.setSize(NodeStack.getSize() + 1); + } + + /** + * Value to be taken off the stack. + * + * @return item : value that is returned. + */ + public Item pop() { + + Item item = (Item) NodeStack.head.getData(); + + NodeStack.head = NodeStack.head.getPrevious(); + NodeStack.head.setNext(null); + + NodeStack.setSize(NodeStack.getSize() - 1); + + return item; + } + + /** + * Value that is next to be taken off the stack. + * + * @return item : the next value that would be popped off the stack. + */ + public Item peek() { + return (Item) NodeStack.head.getData(); + } + + /** + * If the stack is empty or there is a value in. + * + * @return boolean : whether or not the stack has anything in it. + */ + public boolean isEmpty() { + return NodeStack.getSize() == 0; + } + + /** + * Returns the size of the stack. + * + * @return int : number of values in the stack. + */ + public int size() { + return NodeStack.getSize(); + } + + /** + * Print the contents of the stack in the following format. + * + * x <- head (next out) + * y + * z <- tail (first in) + * . + * . + * . + * + */ + public void print() { + for(NodeStack n = NodeStack.head; n != null; n = n.previous) { + System.out.println(n.getData().toString()); + } + } + + /** Getters and setters (private) */ + private NodeStack getHead() { + return NodeStack.head; + } + + private static void setHead(NodeStack ns) { + NodeStack.head = ns; + } + + private NodeStack getNext() { + return next; + } + + private void setNext(NodeStack next) { + this.next = next; + } + + private NodeStack getPrevious() { + return previous; + } + + private void setPrevious(NodeStack previous) { + this.previous = previous; + } + + private static int getSize() { + return size; + } + + private static void setSize(int size) { + NodeStack.size = size; + } + + private Item getData() { + return this.data; + } + + private void setData(Item item) { + this.data = item; + } +}