Tutorials
Resources
Forum
Reviews
Communities
Interview
Jobs
Projects
Training
Your
Ad
Here
Silverlight Games
|
Mentor
|
Code Converter
|
Articles
|
Code Factory
|
Computer Jokes
|
Members
|
Peer Appraisal
|
IT Companies
|
Bookmarks
|
Polls
|
Revenue Sharing
|
Lobby
|
Gift Shop
|
Prizes & Awards
My Profile
Sign In
Register
AdSense Revenue
Active Members
Today
Asheej T K
(177)
Alwyn
(116)
Manindra Upadh...
(76)
Last 7 Days
Alwyn
(1038)
Asheej T K
(750)
Manindra Upadh...
(542)
more...
Resources
»
Code Snippets
»
General
»
Static list Head and tail pointer in c++
Posted Date: 24 Aug 2009
Resource Type:
Code Snippets
Category:
General
Author:
Santosh Kumar Singh
Member Level:
Gold
Rating:
Points
: 4
////////////////////////////////////////
#include
#include
////////////////////////////////////////
// The ListEntry class.
////////////////////////////////////////
class ListEntry
{
public:
// Static list head pointer.
static ListEntry* firstentry;
private:
// Static list tail pointer.
static ListEntry* lastentry;
char* listvalue;
ListEntry* nextentry;
public:
ListEntry(char*);
~ListEntry()
{ delete [] listvalue;}
ListEntry* NextEntry() const
{ return nextentry; };
void display() const
{ std::cout << listvalue << std::endl; }
};
// Define the static pointers.
ListEntry* ListEntry::firstentry; // static list head pointer.
ListEntry* ListEntry::lastentry; // static list tail pointer.
// The constructor.
ListEntry::ListEntry(char* s)
{
if (firstentry == 0)
firstentry = this;
if (lastentry != 0)
lastentry->nextentry = this;
lastentry = this;
listvalue = new char[std::strlen(s)+1];
std::strcpy(listvalue, s);
nextentry = 0;
}
////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
// Read in some names.
while (1)
{
std::cout << "\nEnter a name ('end' when done): ";
char name[25];
std::cin >> name;
if (std::strncmp(name, "end", 3) == 0)
break;
// Make a list entry of the name.
new ListEntry(name);
}
// Get a pointer to the first list entry.
ListEntry* next = ListEntry::firstentry;
// Display the names.
while (next != 0)
{
next->display();
ListEntry* hold = next;
next = next->NextEntry();
delete hold;
}
return 0;
}
Responses
Author:
Miss Meetu Choudhary
27 Aug 2009
Member Level:
Diamond
Points
: 2
Must add description to your code
Feedbacks
Popular Tags
What are tags ?
Search Tags
Sign In
to add tags.
Static list Head and tail pointer in c++
.
Post Feedback
This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must
Sign In
to post a response.
Next Resource:
Add the entry to the linked list using c++
Previous Resource:
Deletes all array elements in c++
Return to Discussion Resource Index
Post New Resource
Category:
General
Post resources and
earn money
!
More Resources
Add the entry to the linked list using c++
To lock and unlock a folder
Custom Date private members and forwarding reference to compiler in c++
Convert Date to CustomDate via assignment,function argument,initializer andreturn value(c++)
Quicksort code using c++
Get Minimum of 3 variables in c++
dotNet Slackers
About Us
Contact Us
Privacy Policy
Terms Of Use