From 5bdd09f0c5200dcef26d777fa9d028ae3d1365b3 Mon Sep 17 00:00:00 2001 From: "Aravind V. Nair" <22199259+aravindvnair99@users.noreply.github.com> Date: Sun, 30 Sep 2018 23:33:53 +0530 Subject: [PATCH 1/4] Update CONTRIBUTORS.md --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c6d76e6..b7d85d7 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,3 +1,4 @@ # Add yourself in this file if you are a contributor for Hacktoberfest 2018 - Radu Stochitoiu +- Aravind V. Nair ([@AravindVNair99](https://github.com/AravindVNair99)), Computer Science enthusiast mainly interested in web development and cybersecurity [Portfolio Website](https://aravindvnair99.firebaseapp.com), [Blog](https://aravindvnair1999.blogspot.com) From d7cb2fe70b0afbd745dec50072cc81392d3cbc97 Mon Sep 17 00:00:00 2001 From: "Aravind V. Nair" <22199259+aravindvnair99@users.noreply.github.com> Date: Sun, 30 Sep 2018 23:38:51 +0530 Subject: [PATCH 2/4] Create ReverseArrayUsingStack.java --- Java/algorithms/ReverseArrayUsingStack.java | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Java/algorithms/ReverseArrayUsingStack.java diff --git a/Java/algorithms/ReverseArrayUsingStack.java b/Java/algorithms/ReverseArrayUsingStack.java new file mode 100644 index 0000000..e8ae85b --- /dev/null +++ b/Java/algorithms/ReverseArrayUsingStack.java @@ -0,0 +1,27 @@ +//Reverse an array using stack + +import java.util.Scanner; +import java.util.Stack; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n; + System.out.println("Enter the size of the array:"); + n = sc.nextInt(); + Stack st = new Stack(); + int[] a = new int[n]; + System.out.println("\nEnter the elements of the array:"); + for (int i = 0; i < n; i++) { + a[i] = sc.nextInt(); + } + for (int i = 0; i < n; i++) { + st.push(a[i]); + } + System.out.println("\nArray after reversing:"); + for (int i = 0; i < n; i++) { + System.out.println(a[i] = st.pop()); + } + sc.close(); + } +} From af4b99dacc1fd144482e5f4e5cd87e8fa971a0fb Mon Sep 17 00:00:00 2001 From: "Aravind V. Nair" <22199259+aravindvnair99@users.noreply.github.com> Date: Sun, 30 Sep 2018 23:40:01 +0530 Subject: [PATCH 3/4] Create PasswordGenerator.java --- Java/algorithms/PasswordGenerator.java | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Java/algorithms/PasswordGenerator.java diff --git a/Java/algorithms/PasswordGenerator.java b/Java/algorithms/PasswordGenerator.java new file mode 100644 index 0000000..a8398f6 --- /dev/null +++ b/Java/algorithms/PasswordGenerator.java @@ -0,0 +1,29 @@ +// Generate random password of given length + +import java.util.Random; +import java.util.Scanner; + +public class PasswordGenerator { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("Enter the length of the password you require:\n"); + System.out.println(generatePswd(sc.nextInt())); + sc.close(); + } + + static char[] generatePswd(int len) { + System.out.println("\nYour password is:\n"); + String charsCaps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + String chars = "abcdefghijklmnopqrstuvwxyz"; + String nums = "0123456789"; + String symbols = "!@#$%^&*_=+-/€.?<>)"; + String passSymbols = charsCaps + chars + nums + symbols; + Random rnd = new Random(); + char[] password = new char[len]; + int index = 0; + for (int i = 0; i < len; i++) { + password[i] = passSymbols.charAt(rnd.nextInt(passSymbols.length())); + } + return password; + } +} From 54cef571eb18a93e2d5addffc1be004f84f4fe3a Mon Sep 17 00:00:00 2001 From: "Aravind V. Nair" <22199259+aravindvnair99@users.noreply.github.com> Date: Sun, 30 Sep 2018 23:52:41 +0530 Subject: [PATCH 4/4] Create CircularQueueUsingArray.java --- .../CircularQueueUsingArray.java | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 Java/data-structures/CircularQueueUsingArray.java diff --git a/Java/data-structures/CircularQueueUsingArray.java b/Java/data-structures/CircularQueueUsingArray.java new file mode 100644 index 0000000..cb49103 --- /dev/null +++ b/Java/data-structures/CircularQueueUsingArray.java @@ -0,0 +1,102 @@ +import java.util.Scanner; + +public class CircularQueueUsingArray { + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + System.out.print("Enter total no of elements to be in the queue: "); + int maxSize = input.nextInt(); + CircularQueue queue = new CircularQueue(maxSize); + int select; + int term = 0; + while (term == 0) { + System.out.print( + "\nOption:\tTo Do:\n1\tTo enqueue element.\n2\tTo dequeue element.\n3\tTo Display the Queue elements.\n4\tTo Exit the Program.\n\nEnter your option:- "); + select = input.nextInt(); + switch (select) { + case 1: { + System.out.print("\nEnter element to insert in the queue: "); + int ele = input.nextInt(); + queue.enqueue(ele); + break; + } + case 2: { + queue.dequeue(); + break; + } + case 3: { + queue.display(); + break; + } + case 4: { + term = 1; + System.out.println("\nSee you next time!"); + input.close(); + break; + } + default: + System.out.println("\nEnter a valid option."); + } + } + } +} + +class CircularQueue { + int maxSize; + int rear; + int front; + int aQueue[]; + { + rear = -1; + front = -1; + } + + CircularQueue(int maxSize) { + this.maxSize = maxSize; + this.aQueue = new int[maxSize]; + } + + void enqueue(int item) { + if (((rear + 1) % maxSize) == front) { + System.out.println("\nQueue is full"); + } else { + if (rear == front && front == -1) { + front += 1; + } + rear = (rear + 1) % maxSize; + aQueue[rear] = item; + } + } + + void dequeue() { + if (rear == front && rear == -1) { + System.out.println("\nQueue is empty."); + } else { + int item = aQueue[front]; + if (rear == front) { + rear = -1; + front = -1; + } else { + front = (front + 1) % maxSize; + } + System.out.println(item + " is deQueued from the Queue"); + } + } + + void display() { + int tempfront = front; + if (rear == front && rear == -1) { + System.out.println("\nQueue is Empty."); + } else { + System.out.println("\nThe contents of the queue are:- "); + for (int i = 0; i < maxSize; i++) { + if (tempfront != rear) { + System.out.println(aQueue[tempfront]); + tempfront = (tempfront + 1) % maxSize; + } else { + System.out.println(aQueue[rear]); + break; + } + } + } + } +}