Hi,
Link list is very easy to implement in C++. Below is all that you will
ever need to handle linked list. It is Lifo structured list. For the FIFO I hope that by next week you will be able to do it by yourself. Let me know if you don't get it.
Judex
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
//create global variables
void push(int); // add data elements to list
void pop(); // delete data from list
void readp(); // read data
struct link
{
int prime;
link *next;
};
link *first = NULL;
main ()
{
int param,remainder;
push(2);
push(3);
push(5);
push(7);
push(11);
readp();
pop();
readp();
getch();
}
void push(int pp)
{
link *newlink= new link;
newlink ->prime = pp;
newlink->next = first;
first=newlink;
}
void pop()
{
first = first->next;
}
void readp()
{
link *current = first;
while (current != NULL)
{
cout << current->prime;
cout << " ";
current = current->next;
}
}
}
|