A Expression Calculator using Linked Lists!

It’s the longest C project I’ve written to date. I used linked lists in order to make it fast, one node of the list represents a number and its properties and the operator affecting it. Branches are introduced to mimic brackets. The user will give a normal string input like “1+2” and the output will be 3. But what they don’t see is the implementation. The list will include two nodes for 1 and 2 and with their operators(both + in this case). Then the calculation function will go through this list.

When there are brackets, for example : 1+(1+5)/6 the two lists will be made and one will have +1,+5 and it’ll be linked at theĀ appropriate location on the main list which will be like 1+[link_to_list_1]/6 since the calculation is done recursively, when the function reaches the end of the main list other child lists’ values will be assigned and then simplified.

It includes the following preset functions(it only supports one argument functions up to now),

sin, cos, tan, asin, acos, atan. dtor, rtod, fact

Download the source and Linux executable


One thought on “A Expression Calculator using Linked Lists!

  1. great work dude. i just went through with the tom’s calculator he has the same but not logariths and trignometrical values as well.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s