[code]void CircleList::add(string s)
{
Player p;
p.name=s;
if(count==0) // no players at the table
{
// special case: adds a player to an empty table
playerArray[0]=p;
count=1; // adds the first player
whoWasLastToPlay=0; // whoWasLastToPlay at pos 0
}
else
{
for(int i=count-1; i>=whoWasLastToPlay+1; i--)
{
playerArray[i+1]=playerArray[i];
}
playerArray[whoWasLastToPlay+1]=p;
count++;
}
}[/ code]
EddieV223 wrote:
An unsigned int is 4 bytes in 32 or 64 bit OS.
It doesn't have to be. It depends on the compiler.
EddieV223 wrote:
Because string uses a unsigned int it will have the limit as such.
size_t doesn't have to be a typedef for unsigned int. On 64 bit compilers it's often a 64 bit integer. Note that even if sizeof(size_t) == sizeof(unsigned int), it doesn't mean they are necessary the same type.
Zephilinox wrote:
You're right, ints in C++ are either 16-bit or 32-bit, they can't be 64-bit.
Sarcasm?
Thank you, you are getting closer to my point. What ever data type is used will be the limit. Run time limitations are different.
Its really hard to have a conversion about type sizes in c++ since they are not defined. My point about 32 or 64 was ment that it is not defined that the size of an unsigned int will be 8 bytes just cause its a 64 bit build.
For example I can guarantee that on VS2012's implementations, an int is 4 bytes on 32 and 64bit builds.
std::numeric_limits<std::string::size_type>::max() - 1; // this is your code's limit on string size.
void CircleList::add(string s)
{
Player p;
p.name=s;
if(count==0) // no players at the table
{
// special case: adds a player to an empty table
playerArray[0]=p;
count=1; // adds the first player
whoWasLastToPlay=0; // whoWasLastToPlay at pos 0
}
else
{
for(int i=count-1; i>=whoWasLastToPlay+1; i--)
{
playerArray[i+1]=playerArray[i];
}
playerArray[whoWasLastToPlay+1]=p;
count++;
}
}
what I'm trying to do is implement the above array based code as a dynamic, pointer based singly linked list code. Therefore my earlier question as to weather in the following:
where 10 is indeed the data content of "that one node", and since in a linked list each node contains data and a pointer to the next node, can I let the string "whoWasLastToPlay" in the above code be the content of one node. I will continue after your response. Thanks for your help!!
you are correct, it is an int, and it resides(at this point)implicitly in position(or index) 0(zero) in the array. How can I make the following "add" code resemble(ideally mirror)the above "add"code? They are (very) different now.
void CircleList::Add(string s)
{
//assume you have a node called firstNode
//linked list is empty
if (firstNode->nextNode == nullptr)
{
firstNode->nextNode = new node;
firstNode->nextNode->data = whoWasLastToPlay;
firstNode->nextNode->nextNode = nullptr; //really, the constructor of the node should initialize it to nullptr
}
else
{
node *endNode = firstNode;
while (endNode->nextNode != nullptr) //while it points to something
{
//keep moving down the linked list
endNode->nextNode = endNode->nextNode->nextNode;
}
endNode->nextNode = new node;
//add item as the data of the last node
endNode->nextNode->data = item;
endNode->nextNode->nextNode = nullptr;
}
}
considering your code, or mine: how can I make the linked list implementation do what the array implementation is doing, ie, add a player to the group, and increment the count. How does the incrementing loop in the else statement and the playerArray container, and count translate into the linked list version. Is not the arrow operator associated more with structs than classes?
good nite. thanks for your help. I am in the Eastern Standard time zone. It is 8PM, Saturday here. If it is 1AM where you are, then you are either in Europe or in the middle of the Pacific ocean.