Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update chiphers #419

Merged
merged 4 commits into from Apr 15, 2018
Merged

update chiphers #419

merged 4 commits into from Apr 15, 2018

Conversation

@khalil2535
Copy link
Contributor

@khalil2535 khalil2535 commented Apr 14, 2018

changes :-

  • Remove space from Data Structures package name
  • adding docs for RSA.java
  • format ColumnarTranspositionCipher.java and fix English errors
  • fix BalancedBrackets.java
Copy link
Collaborator

@christianbender christianbender left a comment

Good Work! I have some requests.

private static Object[] findElements() {
Object[] charValues = new Object[keyword.length()];
for (int i = 0; i < charValues.length; i++) {
for (int j = 0; j < abecedarium.length(); j++) {

This comment has been minimized.

@christianbender

christianbender Apr 14, 2018
Collaborator

This loop can be avoid with help of the method .indexOf(c) see

This comment has been minimized.

@khalil2535

khalil2535 Apr 14, 2018
Author Contributor

👍

table[i][secondColumnIndex]=table[i][firstColumnIndex];
table[i][firstColumnIndex]=columnToSwitch[i];

private static void switchColumns(Object[][] table, int firstColumnIndex, int secondColumnIndex, Object[] columnToSwitch) {

This comment has been minimized.

@christianbender

christianbender Apr 14, 2018
Collaborator

Please break this line up. max. 80 columns

This comment has been minimized.

@khalil2535

khalil2535 Apr 14, 2018
Author Contributor

👍 done

@christianbender christianbender merged commit b082ecc into TheAlgorithms:master Apr 15, 2018
@shredN

This comment has been minimized.

Copy link

@shredN shredN commented on e5e6fc1 Jul 19, 2018

//Rather use this, As this can perfectly handle the condition where closing brackets are more than opening brackets

package Stacks;

import java.util.Scanner;
import java.util.Stack;

/**
*

  • The nested brackets problem is a problem that determines if a sequence of
  • brackets are properly nested. A sequence of brackets s is considered properly
  • nested if any of the following conditions are true: - s is empty - s has the
  • form (U) or [U] or {U} where U is a properly nested string - s has the form
  • VW where V and W are properly nested strings For example, the string
  • "()()[()]" is properly nested but "[(()]" is not. The function called
  • is_balanced takes as input a string S which is a sequence of brackets and
  • returns true if S is nested and false otherwise.
  • @author akshay sharma
  • @Date: 2017-10-17
  • @author khalil2535

*/
class BalancedBrackets {

/**
 *
 * @param s
 * @return
 */
static boolean is_balanced(String s) {
    Stack<Character> bracketsStack = new Stack<>();
    char[] text = s.toCharArray();
    for (char x : text) {
        switch (x) {
            case '{':
            case '<':
            case '(':
            case '[':
                bracketsStack.push(x);
                break;
            case '}':
                if (bracketsStack.peek() == '{') {
                    bracketsStack.pop();
                    break;
                } else {
                    return false;
                }
            case '>':
                if (bracketsStack.peek() == '<') {
                    bracketsStack.pop();
                    break;
                } else {
                    return false;
                }
            case ')':
                if (bracketsStack.peek() == '(') {
                    bracketsStack.pop();
                    break;
                } else {
                    return false;
                }
            case ']':
                if (bracketsStack.peek() == '[') {
                    bracketsStack.pop();
                    break;
                } else {
                    return false;
                }
        }
    }
    return bracketsStack.empty();
}

/**
 *
 * @param args
 * @TODO remove main method and Test using JUnit or other methodology
 */
public static void main(String args[]) {
    try (Scanner in = new Scanner(System.in)) {
        System.out.println("Enter sequence of brackets: ");
        String s = in.nextLine();
		try {
			if (is_balanced(s)) {
				System.out.println(s + " is balanced");
			} else {
				System.out.println(s + " ain't balanced");
			}
		} catch (Exception e) {
			System.out.println(s + " isn't balanced");
		}
    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.