Solved

Linked List

Posted on 2006-07-04
3
2,448 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

809 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