From 2a0f902a241d397252eb80017090f842edb381f9 Mon Sep 17 00:00:00 2001 From: Maria Fernandes Date: Tue, 7 Jan 2025 19:48:30 -0800 Subject: [PATCH 1/6] Testing git --- .idea/.gitignore | 3 +++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 7 +++++++ Exercise_1.java | 3 ++- PreCourse-1.iml | 11 +++++++++++ 6 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 PreCourse-1.iml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..26d33521a --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..639900d13 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..a866e1a9f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..830674470 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Exercise_1.java b/Exercise_1.java index 314a3cb45..be0cf1907 100644 --- a/Exercise_1.java +++ b/Exercise_1.java @@ -36,7 +36,8 @@ int peek() // Driver code class Main { public static void main(String args[]) - { + { + // Stack Stack s = new Stack(); s.push(10); s.push(20); diff --git a/PreCourse-1.iml b/PreCourse-1.iml new file mode 100644 index 000000000..b107a2dd8 --- /dev/null +++ b/PreCourse-1.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file From 594c98fe32f35afe4574abb19be12fd55928a088 Mon Sep 17 00:00:00 2001 From: Maria Fernandes Date: Tue, 7 Jan 2025 20:14:22 -0800 Subject: [PATCH 2/6] git ignore file --- .gitignore | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..4d7dc8bec --- /dev/null +++ b/.gitignore @@ -0,0 +1,56 @@ +# Ignore node_modules directory (for Node.js projects) +node_modules/ + +# Ignore logs and temporary files +*.log +*.tmp + +# Ignore OS generated files +.DS_Store +Thumbs.db + +# Ignore IDE/editor specific files +.vscode/ +.idea/ +*.suo +*.user +*.sln +*.swp + +# Ignore Python-specific files +__pycache__/ +*.py[cod] + +# Ignore Java-specific files +*.class + +# Ignore build outputs +dist/ +build/ + +# Ignore compiled code +*.o +*.out +*.a +*.so + +# Ignore environment files +.env +.env.local + +# Ignore coverage reports +coverage/ +*.lcov + +# Ignore database files +*.sqlite +*.db + +# Ignore archive files +*.zip +*.tar.gz +*.rar + +# Ignore custom local files +secret-config.json +debug.log \ No newline at end of file From c7e44ee003c7d12168d8d33f41046224b9155121 Mon Sep 17 00:00:00 2001 From: Maria Fernandes Date: Wed, 15 Jan 2025 21:22:18 -0800 Subject: [PATCH 3/6] Precourse 1 --- Exercise_1.java | 47 --------------------- Exercise_2.java | 52 ----------------------- Exercise_3.java | 70 ------------------------------- LinkedList.java | 94 ++++++++++++++++++++++++++++++++++++++++++ PreCourse-1.iml | 11 ----- StackAsArray.java | 85 ++++++++++++++++++++++++++++++++++++++ StackAsLinkedList.java | 91 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 270 insertions(+), 180 deletions(-) delete mode 100644 Exercise_1.java delete mode 100644 Exercise_2.java delete mode 100644 Exercise_3.java create mode 100644 LinkedList.java delete mode 100644 PreCourse-1.iml create mode 100644 StackAsArray.java create mode 100644 StackAsLinkedList.java diff --git a/Exercise_1.java b/Exercise_1.java deleted file mode 100644 index be0cf1907..000000000 --- a/Exercise_1.java +++ /dev/null @@ -1,47 +0,0 @@ -class Stack { - //Please read sample.java file before starting. - //Kindly include Time and Space complexity at top of each file - static final int MAX = 1000; - int top; - int a[] = new int[MAX]; // Maximum size of Stack - - boolean isEmpty() - { - //Write your code here - } - - Stack() - { - //Initialize your constructor - } - - boolean push(int x) - { - //Check for stack Overflow - //Write your code here - } - - int pop() - { - //If empty return 0 and print " Stack Underflow" - //Write your code here - } - - int peek() - { - //Write your code here - } -} - -// Driver code -class Main { - public static void main(String args[]) - { - // Stack - Stack s = new Stack(); - s.push(10); - s.push(20); - s.push(30); - System.out.println(s.pop() + " Popped from stack"); - } -} diff --git a/Exercise_2.java b/Exercise_2.java deleted file mode 100644 index 5a9c4868c..000000000 --- a/Exercise_2.java +++ /dev/null @@ -1,52 +0,0 @@ -public class StackAsLinkedList { - - StackNode root; - - static class StackNode { - int data; - StackNode next; - - StackNode(int data) - { - //Constructor here - } - } - - - public boolean isEmpty() - { - //Write your code here for the condition if stack is empty. - } - - public void push(int data) - { - //Write code to push data to the stack. - } - - public int pop() - { - //If Stack Empty Return 0 and print "Stack Underflow" - //Write code to pop the topmost element of stack. - //Also return the popped element - } - - public int peek() - { - //Write code to just return the topmost element without removing it. - } - - //Driver code - public static void main(String[] args) - { - - StackAsLinkedList sll = new StackAsLinkedList(); - - sll.push(10); - sll.push(20); - sll.push(30); - - System.out.println(sll.pop() + " popped from stack"); - - System.out.println("Top element is " + sll.peek()); - } -} diff --git a/Exercise_3.java b/Exercise_3.java deleted file mode 100644 index fb66d329d..000000000 --- a/Exercise_3.java +++ /dev/null @@ -1,70 +0,0 @@ -import java.io.*; - -// Java program to implement -// a Singly Linked List -public class LinkedList { - - Node head; // head of list - - // Linked list Node. - // This inner class is made static - // so that main() can access it - static class Node { - - int data; - Node next; - - // Constructor - Node(int d) - { - //Write your code here - } - } - - // Method to insert a new node - public static LinkedList insert(LinkedList list, int data) - { - // Create a new node with given data - - // If the Linked List is empty, - // then make the new node as head - - // Else traverse till the last node - // and insert the new_node there - - // Insert the new_node at last node - // Return the list by head - - } - - // Method to print the LinkedList. - public static void printList(LinkedList list) - { - // Traverse through the LinkedList - - // Print the data at current node - - // Go to next node - } - - // Driver code - public static void main(String[] args) - { - /* Start with the empty list. */ - LinkedList list = new LinkedList(); - - // - // ******INSERTION****** - // - - // Insert the values - list = insert(list, 1); - list = insert(list, 2); - list = insert(list, 3); - list = insert(list, 4); - list = insert(list, 5); - - // Print the LinkedList - printList(list); - } -} \ No newline at end of file diff --git a/LinkedList.java b/LinkedList.java new file mode 100644 index 000000000..33b93ed65 --- /dev/null +++ b/LinkedList.java @@ -0,0 +1,94 @@ +// Java program to implement +// a Singly Linked List + +/* +Space Complexity +O(n) n is the number of elements in the linkedlist + +Time Complexity +insert O(n) n is the number of elements in the linkedlist to be traversed +printList O(n) n is the number of elements in the linkedlist +*/ +public class LinkedList { + + Node head; // head of list + + // Linked list Node. + // This inner class is made static + // so that main() can access it + static class Node { + + int data; + Node next; + + // Constructor + Node(int d) + { + //Write your code here + data=d; + next=null; + } + } + + // Method to insert a new node + public static LinkedList insert(LinkedList list, int data) + { + // Create a new node with given data + Node newNode=new Node(data); + + + // If the Linked List is empty, + // then make the new node as head + if(list.head==null){ + list.head=newNode; + } + else{ + // Else traverse till the last node + // and insert the new_node there + Node last=list.head; + while(last.next!=null){ + last=last.next; + } + + // Insert the new_node at last node + last.next=newNode; + } + + // Return the list by head + return list; + } + + // Method to print the LinkedList. + public static void printList(LinkedList list) + { + // Traverse through the LinkedList + Node node=list.head; + while(node!=null){ + // Print the data at current node + System.out.println(node.data); + // Go to next node + node=node.next; + } + } + + // Driver code + public static void main(String[] args) + { + /* Start with the empty list. */ + LinkedList list = new LinkedList(); + + // + // ******INSERTION****** + // + + // Insert the values + list = insert(list, 1); + list = insert(list, 2); + list = insert(list, 3); + list = insert(list, 4); + list = insert(list, 5); + + // Print the LinkedList + printList(list); + } +} \ No newline at end of file diff --git a/PreCourse-1.iml b/PreCourse-1.iml deleted file mode 100644 index b107a2dd8..000000000 --- a/PreCourse-1.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/StackAsArray.java b/StackAsArray.java new file mode 100644 index 000000000..2c6ddacc8 --- /dev/null +++ b/StackAsArray.java @@ -0,0 +1,85 @@ +/* +Space Complexity +O(n) n is the number of elements in the stack + +Time Complexity +isEmpty O(1) +push(int x) O(1) +pop() O(1) +peek() O(1) +*/ +class StackAsArray { + //Please read sample.java file before starting. + //Kindly include Time and Space complexity at top of each file + static final int MAX = 1000; + int top; + int a[] = new int[MAX]; // Maximum size of Stack + + boolean isEmpty() + { + //Write your code here + if(top==-1){ + System.out.println("Stack is Empty"); + return true; + } + return false; + } + + StackAsArray() + { + //Initialize your constructor + top = -1; + } + + boolean push(int x) + { + //Check for stack Overflow + //Write your code here + if(top==MAX-1){ + System.out.println("Stack Overflow"); + return false; + } + + top=top+1; + a[top]=x; + System.out.println(x+" is pushed onto the stack"); + return true; + } + + int pop() + { + //If empty return 0 and print " Stack Underflow" + //Write your code here + if(top==-1){ + System.out.println("Stack Underflow"); + return 0; + } + + int value=a[top]; + top=top-1; + return value; + } + + int peek() + { + //Write your code here + if(top==-1){ + System.out.println("Stack Underflow"); + return 0; + } + return a[top]; + } +} + +// Driver code +class Main { + public static void main(String args[]) + { + // Stack + StackAsArray s = new StackAsArray(); + s.push(10); + s.push(20); + s.push(30); + System.out.println(s.pop() + " Popped from stack"); + } +} diff --git a/StackAsLinkedList.java b/StackAsLinkedList.java new file mode 100644 index 000000000..1cb071d94 --- /dev/null +++ b/StackAsLinkedList.java @@ -0,0 +1,91 @@ +/* +Space Complexity +O(n) n is the number of elements in the stack + +Time Complexity +isEmpty O(1) +push(int data) O(1) +pop() O(1) +peek() O(1) +*/ +public class StackAsLinkedList { + + StackNode root; + + StackAsLinkedList(){ + root=null; + } + + static class StackNode { + int data; + StackNode next; + + StackNode(int data) + { + //Constructor here + this.data=data; + this.next=null; + } + } + + + public boolean isEmpty() + { + //Write your code here for the condition if stack is empty. + if(root==null){ + System.out.println("Stack Underflow"); + return true; + } + return false; + } + + public void push(int data) + { + //Write code to push data to the stack. + StackNode newNode=new StackNode(data); + if(newNode==null){ + System.out.println("Stack Overflow"); + return; + } + newNode.next=root; + System.out.println(newNode.data+" is pushed onto the stack"); + root=newNode; + } + + public int pop() + { + //If Stack Empty Return 0 and print "Stack Underflow" + //Write code to pop the topmost element of stack. + //Also return the popped element + if(isEmpty()){ + return 0; + } + StackNode temp= root; + root=root.next; + return temp.data; + } + + public int peek() + { + //Write code to just return the topmost element without removing it. + if(isEmpty()){ + return 0; + } + return root.data; + } + + //Driver code + public static void main(String[] args) + { + + StackAsLinkedList sll = new StackAsLinkedList(); + + sll.push(10); + sll.push(20); + sll.push(30); + + System.out.println(sll.pop() + " popped from stack"); + + System.out.println("Top element is " + sll.peek()); + } +} From bf39baa89e7439749e677df978768103f7a67a90 Mon Sep 17 00:00:00 2001 From: Maria-Fernandes Date: Wed, 15 Jan 2025 21:25:06 -0800 Subject: [PATCH 4/6] Delete .idea directory --- .idea/.gitignore | 3 --- .idea/misc.xml | 6 ------ .idea/modules.xml | 8 -------- .idea/vcs.xml | 7 ------- 4 files changed, 24 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d33521a..000000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 639900d13..000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index a866e1a9f..000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 830674470..000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file From fd2f596ce37e3a710f96f4fb3d535b8167f3f99c Mon Sep 17 00:00:00 2001 From: mariafernandes Date: Wed, 15 Jan 2025 21:48:34 -0800 Subject: [PATCH 5/6] PreCourse 1 Submission --- StackAsArray.java => Exercise_1.java | 0 StackAsLinkedList.java => Exercise_2.java | 6 +++--- LinkedList.java => Exercise_3.java | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) rename StackAsArray.java => Exercise_1.java (100%) rename StackAsLinkedList.java => Exercise_2.java (89%) rename LinkedList.java => Exercise_3.java (87%) diff --git a/StackAsArray.java b/Exercise_1.java similarity index 100% rename from StackAsArray.java rename to Exercise_1.java diff --git a/StackAsLinkedList.java b/Exercise_2.java similarity index 89% rename from StackAsLinkedList.java rename to Exercise_2.java index 1cb071d94..eb2d301c8 100644 --- a/StackAsLinkedList.java +++ b/Exercise_2.java @@ -8,11 +8,11 @@ isEmpty O(1) pop() O(1) peek() O(1) */ -public class StackAsLinkedList { +public class Exercise_2 { StackNode root; - StackAsLinkedList(){ + Exercise_2(){ root=null; } @@ -78,7 +78,7 @@ public int peek() public static void main(String[] args) { - StackAsLinkedList sll = new StackAsLinkedList(); + Exercise_2 sll = new Exercise_2(); sll.push(10); sll.push(20); diff --git a/LinkedList.java b/Exercise_3.java similarity index 87% rename from LinkedList.java rename to Exercise_3.java index 33b93ed65..0df3f700f 100644 --- a/LinkedList.java +++ b/Exercise_3.java @@ -9,7 +9,7 @@ insert O(n) n is the number of elements in the linkedlist to be traversed printList O(n) n is the number of elements in the linkedlist */ -public class LinkedList { +public class Exercise_3 { Node head; // head of list @@ -31,7 +31,7 @@ static class Node { } // Method to insert a new node - public static LinkedList insert(LinkedList list, int data) + public static Exercise_3 insert(Exercise_3 list, int data) { // Create a new node with given data Node newNode=new Node(data); @@ -59,7 +59,7 @@ public static LinkedList insert(LinkedList list, int data) } // Method to print the LinkedList. - public static void printList(LinkedList list) + public static void printList(Exercise_3 list) { // Traverse through the LinkedList Node node=list.head; @@ -75,7 +75,7 @@ public static void printList(LinkedList list) public static void main(String[] args) { /* Start with the empty list. */ - LinkedList list = new LinkedList(); + Exercise_3 list = new Exercise_3(); // // ******INSERTION****** From 54c91d5ebae19d9c54ade021f83627ec5589f750 Mon Sep 17 00:00:00 2001 From: Maria-Fernandes Date: Wed, 15 Jan 2025 21:49:39 -0800 Subject: [PATCH 6/6] Delete .gitignore --- .gitignore | 56 ------------------------------------------------------ 1 file changed, 56 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 4d7dc8bec..000000000 --- a/.gitignore +++ /dev/null @@ -1,56 +0,0 @@ -# Ignore node_modules directory (for Node.js projects) -node_modules/ - -# Ignore logs and temporary files -*.log -*.tmp - -# Ignore OS generated files -.DS_Store -Thumbs.db - -# Ignore IDE/editor specific files -.vscode/ -.idea/ -*.suo -*.user -*.sln -*.swp - -# Ignore Python-specific files -__pycache__/ -*.py[cod] - -# Ignore Java-specific files -*.class - -# Ignore build outputs -dist/ -build/ - -# Ignore compiled code -*.o -*.out -*.a -*.so - -# Ignore environment files -.env -.env.local - -# Ignore coverage reports -coverage/ -*.lcov - -# Ignore database files -*.sqlite -*.db - -# Ignore archive files -*.zip -*.tar.gz -*.rar - -# Ignore custom local files -secret-config.json -debug.log \ No newline at end of file