Solved

Using subscript notation in linked list in C++

Posted on 2003-10-22
4
295 Views
Last Modified: 2008-03-17
Hi,I’m writing a program to illustrate the work of psedourandom sequence generator-LFSR(Linear Feedback Shift Register).
Input   :  initial state of LFSR,primitive polynomial.
Output : psedourandom sequence(a combination of initial state by mod 2)
Since the length of LFSR and the polynomial are given by the user when he runs program, i decided to use linked list to contain all the state of LFSR. But then I stuck in how to use subscript notation. Say,for example I have the length of LFSR n=4 and the polynomial f(x)=x^4+x+1.It means in the linked list I have a[i+4]=a[i]+a[i+1] (a[0]-a[3] are given by the user)(assume it like an unlimited array ),but I don’t know how to handle it.Please I need your help!!!
Here’s part of my code:
     #include <iostream.h>
     // object to add to list
       class Data
       {
       public:
         Data() { itsValue = 0;}
         Data(int Position):itsPosition(Position){}
         Data(int data,int Position):itsValue(data),its Position (Position){}
         ~Data(){}
         int GetValue() const { return itsValue; }
         int Get Position ()const{return its Position;}
       private:
         int itsValue;
         int its Position;
       };

      // manages list, orders by its Position.
       class Node
       {
       public:
         Node (Data*);
         ~Node();
         void SetNext(Node * node) { itsNext = node; }
         Node * GetNext() const { return itsNext; }
         Data * GetData() const { return itsData; }
         void Insert(Node *);        
       private:
         Data *itsData;
         Node * itsNext;
       };

       Node::Node(Data* pData):
       itsData(pData),
       itsNext(0)
       {}

       Node::~Node()
       {
         delete itsData;
         itsData = 0;
         delete itsNext;
         itsNext = 0;
       }

       void Node::Insert(Node* newNode)
       {
         if (!itsNext)
            itsNext = newNode;
         else
         {
               newNode->SetNext(itsNext);
               itsNext = newNode;
         }
       }

      int main()
      {
         int nbr;
         cout<<"Enter the number of registers: ";
         cin>>nbr;
         Node *pNode = 0;
         Data * pData = new Data(0,-1);
         int data;
         Node *pHead = new Node(pData);
         for(int i=0;i<nbr;)
         {
            cout << "Value of register "<<i<<"is: ";
            cin >>data ;
            if (data!=0&&data!=1)
            {
               cout<<"Entry is not correct";
               break;
            }
            pData = new Data(data,i);
            pNode = new Node(pData);
            pHead->Insert(pNode);
            i++;
         }
         WHAT CAN I DO FURTHER?!!!
         return 0;
 }
   
0
Comment
Question by:Scarecrow248
  • 2
4 Comments
 
LVL 4

Expert Comment

by:Zonebit
Comment Utility
0
 

Author Comment

by:Scarecrow248
Comment Utility
Thanks a lot for your help. Your tutorials have helped me alot
0
 
LVL 4

Accepted Solution

by:
Zonebit earned 125 total points
Comment Utility
Scarecrow,

Glad to help out.  Your thanks (and your points) are much appreciated.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
zeroFront challenge 7 70
changeXy challenge 13 56
How  do I get an older program to run in Windows 10? 20 79
recursion example 16 66
Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

762 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

9 Experts available now in Live!

Get 1:1 Help Now