#include<iostream>
using namespace std;
class linkedlist
{private:
llink* firstelem;
.....................................
struct llink
{
int elem;
llink* nextelem;
}
......................................//when i take the struct out the class definition , the program
works well.but just like this it doesn't working! i am confused .
...........................................................................
public:
linkedlist(void);
~linkedlist(void);
void AddElement(int elem1);
void DisplayList(void);
};
linkedlist::linkedlist()
{
firstelem=NULL;
}
linkedlist::~linkedlist(void)
{ }
void linkedlist::AddElement(int elem1)
{
llink* newlink=new llink;
newlink->elem=elem1;
newlink->nextelem=firstelem;
firstelem=newlink;
}
void linkedlist::DisplayList()
{ llink* currentelem=firstelem;
while(currentelem!=NULL)
{
cout<<currentelem->elem<<"-";
currentelem=currentelem->nextelem;
}
cout<<"END"<<endl;
}
int main()
{
linkedlist TestList;
TestList.AddElement(5);
TestList.AddElement(54);
TestList.AddElement(3);
TestList.AddElement(25);
TestList.DisplayList();
return 0;
}
wu7jian 0 Newbie Poster
jhdobbins 0 Junior Poster
wu7jian 0 Newbie Poster
jhdobbins 0 Junior Poster
Narue 5,707 Bad Cop Team Colleague
wu7jian 0 Newbie Poster
Lerner 582 Nearly a Posting Maven
wu7jian 0 Newbie Poster
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.