Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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.

share|improve this answer
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. – delnan Sep 25 '12 at 11:42
@delnan Definitely something to keep in mind. – World Engineer Sep 25 '12 at 11:46

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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