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
(142)
Manindra Upadh...
(76)
Avinash Mohan
(44)
Last 7 Days
Alwyn
(922)
Asheej T K
(715)
Manindra Upadh...
(542)
more...
Resources
»
Code Snippets
»
General
»
Add the entry to the linked list using 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
{
char* listvalue;
ListEntry* preventry;
public:
ListEntry(char*);
~ListEntry()
{ delete [] listvalue; }
ListEntry* PrevEntry() const
{ return preventry; };
void display() const
{ std::cout << std::endl << listvalue; }
// Use the 'this' pointer to chain the list.
void AddEntry(ListEntry& le)
{ le.preventry = this; }
};
// The constructor definition.
ListEntry::ListEntry(char* s)
{
listvalue = new char[std::strlen(s)+1];
std::strcpy(listvalue, s);
preventry = 0;
}
////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
ListEntry* prev = 0;
// Read in some names.
while (1)
{
std::cout << std::endl
<< "Enter 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.
ListEntry* list = new ListEntry(name);
// Add the entry to the linked list.
if (prev != 0)
prev->AddEntry(*list);
prev = list;
}
// Display the names in reverse order.
while (prev != 0)
{
prev->display();
ListEntry* hold = prev;
prev = prev->PrevEntry();
// Delete the ListEntry object.
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.
Add the entry to the linked list using 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:
To lock and unlock a folder
Previous Resource:
Static list Head and tail pointer in c++
Return to Discussion Resource Index
Post New Resource
Category:
General
Post resources and
earn money
!
More Resources
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++
Template definition using c++
dotNet Slackers
About Us
Contact Us
Privacy Policy
Terms Of Use