include <iostream>

using namespace std;

class Lists{
public:
void insert_head(int insert);
void remove_head();
void insert_tail(int insert);
void print();
Lists();
private:
Node *head;
Node *tail;
};

struct Node{
int data;
Node *link;
};

int main()
{
Lists temp;
temp.print();

return 0;
system("PAUSE");

}

Lists::Lists(){
head = new Node;
head->Link=tail;
tail->Link=NULL;
}

void Lists::insert_head(int insert){
Node *temp;
temp->data=insert;
temp->link=head->link;
head->link=temp; //add new Node,
}

void Lists::insert_tail(int insert){
Node *temp;
temp->data=insert;
temp->link=NULL;
tail->link=temp;
}

void Lists::print(){
Node *current=head;
while(current->link==NULL){
cout << current->data << endl;
current=current->link;
}
}

void Lists::remove_head(){
Node *temp=head->link;
head->link=temp->link;
delete temp;
}

What is the problem you are facing.?
Please give further detail.

Comments
After 5 months, do you really think he cares now?

Seeing as this thread is 5 months old, I guess replying to this is pretty much pointless. But seeing as umesh and Rubberman have resurrected it, I figured "what the heck?!". There are a few obvious errors in the code that I can see (other than the lack of code tags and indentation). So here goes:

  1. The 'Node' structure should be declared before the 'Lists' class.
    Because 'Node' is a member of the 'Lists' class, the compiler will need Node to be declared/defined before the 'Lists' class, otherwise it will throw errors about 'Node' being undefined.

  2. The 'tail' member of the 'Lists' class should be initialised in the class constructor.
    As the OPs code stands, the lists 'tail' member is completely uninitialised. So the call to temp.print() in main() will almost certainly cause a segfault/crash at runtime when it attempts to access the tail of the list.

  3. In the 'Lists' class constructor, it should be noted that the 'Node' structure doesn't have a member called 'Link', but it does have a member called 'link'. So the lines 'head->Link=tail;' and 'tail->Link=NULL;' should be edited appropriately.

  4. In the main function the call to 'system("PAUSE")' should be made before the return statement, not after it! In fact if you want to be completely anal about it, system("PAUSE") should not be used at all. But whatever floats the OP's boat!

There may well be other problems/errors in the OP's code, but the four problems listed above stuck out instantly!

Edited 4 Years Ago by JasonHippy

This article has been dead for over six months. Start a new discussion instead.