Hi, I have to write a code which should allow to append and item to a list. That is FIFO Logic, First In First Out, but I cannot think of anything of that kind actually.

I mean, I should run the list until the last pointer, and then make it point to the new object. The only thing that comes in my mind is to write a LIFO list and then reverse it, but I bet there could be something better. University Exam tomorrow: sorry for all these questions!
Any Idea?

Nevermind, I solved it: It was a stupid question!

Just for the noobs who will think like me:

struct Bingo{
	int iValue;
	Bingo *next;
	Bingo *prev;
};

void addValue(Bingo*&, int);
void printValue(Bingo*);

int main(){
	Bingo *bingo=NULL;
	addValue(bingo,2);
	printValue(bingo);
	addValue(bingo,6);
	printValue(bingo);
	addValue(bingo,54);
	printValue(bingo);
	addValue(bingo,90);
	printValue(bingo);
	addValue(bingo,12);
	printValue(bingo);
	addValue(bingo,23);
	printValue(bingo);
	addValue(bingo,78);
	printValue(bingo);
	std::cin.get();
	return 0;
}

void addValue(Bingo*& bingo, int iVal){
	Bingo *New,*temp;
	New = new Bingo;
	New->iValue = iVal;
	New->next=NULL;
	New->prev=NULL;
	if(bingo!=0){
		for(temp=bingo;temp->next!=NULL;temp=temp->next){}
		temp->next=New;
	}
	else{
		New->next = bingo;
		bingo = New;
	}
}

void printValue(Bingo *bingo){
	using namespace std;
	Bingo *temp;
	for(temp=bingo;temp!=NULL;temp=temp->next){
		cout << "Yo! Number: " << temp->iValue << endl;
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.