📄 pr11024.cpp
字号:
////////////////////////////////////////
// File Name: pr11024.cpp
////////////////////////////////////////
#include <iostream>
#include <cstring>
////////////////////////////////////////
// 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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -