[Solved] how do i Convert the C to javascript [closed]

A little help. C | JS —————–|—————— int x; | var x; —————–|—————— int xs[n]; | var xs = []; —————–|—————— printf(…) | console.log(…) —————–|—————— int f (int x) { | function f (x) { … | … return y; | return y; } | } The remaining syntax from your post is almost identical … Read more

[Solved] Dynamic Character Array – Stack

A working variation of my solution appears below. The reason I had to do it this way is because while I was able to dereference (**Array)[MAX_FILENAME_AND_PATHNAME_LEN] I was only able to modify the first string array in the array. The string array was initialized and filled several strings. While I could reference a string contained … Read more

[Solved] Use memory on stack

why not the program crash, or print some random garbage? The program will not crash as you are not accessing any illegal memory. The stack memory is a part of your program and as long as you are accessing the memory in a valid range the program will not crash. Yes, you can modify the … Read more

[Solved] Parenthesis/Brackets Matching using Stack algorithm

Your code has some confusion in its handling of the ‘{‘ and ‘}’ characters. It should be entirely parallel to how you handle ‘(‘ and ‘)’. This code, modified slightly from yours, seems to work properly: public static boolean isParenthesisMatch(String str) { if (str.charAt(0) == ‘{‘) return false; Stack<Character> stack = new Stack<Character>(); char c; … Read more

[Solved] Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character

The first mistake is pushing all the characters on the stack outside of the if statement. Also you should check if stack is empty before removing items from it. Otherwise EmptyStackException is thrown. // stack1.push(S.charAt(i)); <– remove this line if (S.charAt(i)!=’#’) { stack1.push(S.charAt(i)); }else if (!stack1.isEmpty()) { // <– add this check stack1.pop(); } The … Read more

[Solved] How to delete the book that have been input and how to make the title, language, and name doesn’t error if we put space on it? [closed]

If you want to enter data per line, here is an example: class Book { int number; int year; std::string language std::string name; std::string title; public: friend std::istream& operator>>(std::istream& input, Book& b); //… }; std::istream& operator>>(std::istream& input, Book& b) { std::string text_line; std::getline(input, text_line); std::istringstream text_stream(text_line); text_stream >> b.number >> b.year >> b.language >> b.name … Read more

[Solved] std stack performance issues [closed]

The many comments (and even answers) focus on the risks in your implementation. Yet the question stands. As directly demonstrated below rectifying the perceived code shortcomings would not change anything significant about the performance. Here is the OP’s code modified to be (A) safe, and (B) supporting the same operations as std::stack, and (C) reserving … Read more

[Solved] Confusion in stack pointer [closed]

This is how a stack works: You push elements into it like this. The freshly added elements are always “on top” since it is a Last in First Out (LIFO) structure. You can only access the top element: Then You can pop these elements, but pop always removes the top one, like this: If i … Read more