Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8780399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:02:13+00:00 2026-06-13T20:02:13+00:00

How to improve a data structure for storing functions in arithmetic parser converting from

  • 0

How to improve a data structure for storing functions in arithmetic parser converting from infix to postfix notation?

At this moment I am using an array of char arrays:

char *funct[] = { "sin", "cos", "tan"... }
char text[] = "tan";

This impementation is a little bit confused and leads to the following comparisions, if we test char to be a function

if ( strcmp ( funct[0], text) == 0 ) || ( strcmp ( funct[1], "text ) == 0 ) || ( strcmp ( func[2], text) == 0 ))
{
  ... do something
}

( or to the for cycle version).

If there are a lot of functions (and a lot of comparisions), the index referencing leads to errors and it is not clear. There is also a necessity to change the index when we remove/add a new function….

How to improve such a structure so as it is easy to read, easy to maintain and easy to scale up?

I was thinking about enum

typedef enum
{
  Fsin=0,
  Fcos,
  Ftan
} TFunctions;

which results to

if ( strcmp ( funct[Fsin], text) == 0 ) || ( strcmp ( funct[Fcos], "text ) == 0 ) || ( strcmp ( func[Ftan], text) == 0 ))
{
...

but there may be a better solution…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:02:14+00:00Added an answer on June 13, 2026 at 8:02 pm

    You can use std::map.

    enum functions
    {
        sin,
        cos,
        tan
    };
    
    std::map<std::string, unsigned char> func_map;
    func_map["sin"] = sin;
    func_map["cos"] = cos;
    func_map["tan"] = tan;
    
    // then:
    std::string text = "cos";
    
    std::map<char*, unsigned char>::iterator it;
    it = func_map.find(text);
    
    if(it != func_map.end())
    {
        // ELEMENT FOUND
        unsigned char func_id = it->second;
    }
    else
    {
        // NOT FOUND
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just a question to improve my bash skills. I always do this: $ history
I am trying to improve my jQuery skill and I have this bit of
Wanted to write a program to implement a dictionary of words using Tries Data
Is TRIE the most recommended data structure while designing something like a dictionary for
I'm trying to create a matrix data structure in C. I have a struct
I am manipulating many instances of the same data structure which can have one
Implementation Use: Data Structure Lab Exercise for October/28/2011 To do: Implement a Binary Search
This answer is based on this answer . Cha uses arrays in storing login
I have a binary file specification that describes a packetized data structure. Each data
I'm reading binary data (either by network stream or from files) that is predefined

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.