2

I need to develop an GUI application in C# where users can freely add conditional/statement blocks on the algorithm flowchart like the one shown below. By freely, I mean users can add a block on wherever the arrows are.

I'm having some problems brainstorming how to approach this problem, especially what to choose for my datastructure to store the blocks. I was thinking LinkedList since everything follows a linear fashion and every node always has a head and tail, but the If/Else block (b>a) has two branches (heads) to store, so this complicates things a little bit.

How would a smart one approach problems like this? My apologies if this question isn't suited for Programmers stackexchange, but this is more of a conceptual problem rather than implementation problem so I figured this place was appropriate for the question.

enter image description here

2 Answers 2

3

I'd use a graph data structure. They are often implemented using adjacency matrices or adjacency lists. The MSDN has a pretty solid tutorial. The article covers both of the aforementioned structures.

2
  • 2
    An adjacency matrix requires O(|E|^2) space, and is therefore prohibitively expensive for sparse graphs of nontrivial size. And CFGs are definitely very sparse. Adjacency lists are much better for sparse graphs, even though they lose for denser graphs. When you have a hundred nodes but only 150 edges (instead of several thousands) the difference starts to matter. The matrix representation is also very awkward when you don't test for edge presence but want to enumerate the edges, which seems necessary for visualization.
    – user7043
    Sep 25, 2012 at 11:42
  • 1
    @delnan Definitely something to keep in mind.
    – user28988
    Sep 25, 2012 at 11:46
0

I did something similar to this in Java.

I built my own linked list. I had a List of Activities and a List of Connectors.

The Activity class had a integer that acted as the key to the class. It was a sequential counter starting from 0. The Activity class can be extended to draw the different Activity shapes that you need to represent. Each shape has a bounding Rectangle, so you can attach the Connectors to the appropriate places.

The Connector class had two integers, which represented the from Activity and the to Activity. This way, it didn't matter whether or not an Activity had more than one connector.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.