Thanks for that! Okay, so I cleaned it all up. Actually I scrapped it and started over from stubs. Now I am attempting to shuffle a deck of cards, and have an issue. Code first, explanation of issue after:
Header:
Code:
#pragma once
#include "card.h"
class CDeck : public CCard
{
public:
CDeck();
bool empty();
void insert(int index, s_card c);
void insertAtHead(s_card c);
void retrieve(int index, s_card c); // <- This is the function in question
void remove(int index);
void buildDeck();
void shuffleDeck();
protected:
int size();
};
Partial Definition:
Code:
void CDeck::insert(int index, s_card c)
{
if(empty()||index==1)
{
insertAtHead(c);
}
else
{
cardNodeptr cur = head;
int nodenum = 1;
while(cur != NULL && nodenum < index)
{cur = cur->next;}
nodenum++;
}
}
void CDeck::retrieve(int index, s_card c)
{
cardNodeptr cur = head;
for(int x=1; x<=index; x++)
{cur = cur->next;}
c = cur->item;
}
void CDeck::remove(int index)
{
cardNodeptr cur = head;
cardNodeptr prev = NULL;
if(index==1)
{head = head->next;}
else
{
for(int x=1; x<=index; x++)
{
prev = cur;
cur = cur->next;
}
}
delete cur;
}
// and the problematic bloc:
void CDeck::shuffleDeck()
{
int x,y;
for(int count=1; count<=52; count++)
{
x = 1+rand()%52;
y = 1+rand()%52;
insert(y,retrieve(x,));//<- What goes in retrieve's second parameter?
remove(x);
}
}
I suspect I am not using pointers correctly. If I were to call retrieve() from main(), I could just stick an object in there. But I'm not doing that. So what goes in there? How do I tie these pieces together?