Fun question for all the CS nerdz out there:
What is the simplest and/or most efficient function you can write to determine whether a given string has balanced brackets or not?
- Balanced: “(This is balanced)”
- Not Balanced: “(((This is *not*) balanced.”
bool stringHasBalancedBrackets(string inputString)
The function should return true if the brackets are balanced, otherwise false.
(BTW, there is a great solution on Stack Overflow; I’m looking to see what everyone can come up with off the top of their heads.)
My CS300 professor at Portland State University just wrote a fantastic blog post about things he commonly sees in student source code – it’s a great read and helpful for reflecting on your own code and best practices:
I’ve read quite a lot of student code over the years. Some of it is quite good. A lot of it is full of predictable badnesses. These notes attempt to enumerate some of this badness, so that you may avoid it.
This is pretty C-centric in its current form. However, many of its lessons are multilingual. This is a living document, so don’t expect it to be the same next time you look at it. In particular, the numbering may change if something gets inserted in the middle. It is revisioned automatically by Drupal, so feel free to point at a particular revision if you care.
via Things I see in student code | FOB.
Excellent Computer Science resource with tutorials and Java code examples at mycsresource.net – this was very helpful to me in my CS courses…
Linked Lists are a very common way of storing arrays of data. The major benefit of linked lists is that you do not specify a fixed size for your list. The more elements you add to the chain, the bigger the chain gets.
There is more than one type of a linked list, although for the purpose of this tutorial, we’ll stick to singly linked lists (the simplest one). If for example you want a doubly linked list instead, very few simple modifications will give you what you’re looking for. Many data structures (e.g. Stacks, Queues, Binary Trees) are often implemented using the concept of linked lists.
via Linked Lists Tutorial, Examples, and Java code.
Just stumbled on to this problem/fix while writing some C++ code for my CS courses…
warning: deprecated conversion from string constant to ‘char*’
I hadn’t really thought about this much, as previous versions of g++ (such as the 3.4.3 version we’re using on our university systems) never complained about this issue, but g++ 4.2.3 does. The fix, as I found from multiple posts around the web, is to change all function arguments that will be expected to take a string constant from “char *” to “const char *”. For example:
Original Function Prototype:
void class::someFunction(char *);
Updated Function Prototype:
void class::someFunction(const char *);
I’m somewhat new to C++ (OSU taught Java and I code in C# for the day job), so please give me a bit of slack on this one if you’re a seasoned pro. 😉
As always, comments and questions are welcome via my comment box. Thanks for reading!