Solved

# Using subscript notation in linked list in C++

Posted on 2003-10-22
324 Views
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;
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);
i++;
}
WHAT CAN I DO FURTHER?!!!
return 0;
}

0
Question by:Scarecrow248
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 4

Expert Comment

ID: 9599279
0

Author Comment

ID: 9620102
Thanks a lot for your help. Your tutorials have helped me alot
0

LVL 4

Accepted Solution

Zonebit earned 125 total points
ID: 9626878
Scarecrow,

0

## Featured Post

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In this post we will learn different types of Android Layout and some basics of an Android App.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …
###### Suggested Courses
Course of the Month9 days, 2 hours left to enroll