Solved

Linked List

Posted on 2006-07-04
3
2,444 Views
Last Modified: 2013-12-14
create a Linked list to represent the following polynomial
3*x^2*y   +   9x*y^3   +   15*x*y   +  3

I not able to figure out how to proceed with this question...


0
Comment
Question by:sinha_anshul26
3 Comments
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 150 total points
ID: 17040555
>>>> I not able to figure out how to proceed with this question...

You need to parse the given algorithm, extracting each token. You should get a list like

3  number
*  mul
x  variable
^  pow
*  number
y  variable
+  add


The first column type is string cause you might get names and/numbers.

The second could be a enum, e. g.

  enum MathToken { NUMBER, VARIABLE, MUL, POW, ADD, ... };

Any 'row' of the above list can be set to a new item, combining both attributes:

  struct Token
  {
        string        value;
        MathToken token;
  };

Then, you may put the items to a linked list, e. g.

   list<Token> polynomial;

e. g. by using std::list  which you get by

 #include <list>
 using namespace std;

Regards, Alex






0
 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 50 total points
ID: 17040573
I guess you can express each term of the polynomal as a node in a linked list. The coefficient and x and y exponents as members.

e.g.

struct Term {int coeff;int xexp;int yexp;}
typedef std::list<Term> Polynomial;

However, I expect you aren't allowed to use the standard library for your linked list in your assignment.
0
 
LVL 5

Assisted Solution

by:dennis_george
dennis_george earned 50 total points
ID: 17040637
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now