1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#include <iostream>
#include <string>
using namespace std;
class list
{
public:
struct node
{
int num;
string word;
node* link;
};
list::node* push_front (list::node* front,int number,string word )
{
list::node* temp = new list::node;
temp->num = number;
temp->word = word;
temp->link = front;
return temp;
}
list::node* push_back (list::node *conductor,int number,string words)
{
node* newnode = new list::node;
newnode->num = number;
newnode->word = words;
newnode->link = NULL;
while (conductor->link!=NULL)
{
conductor=conductor->link;
}
conductor = newnode;
return conductor;
}
void displaylist (list::node *conductor)
{
while(conductor!=NULL)
{
cout<<conductor->word;
cout<<conductor->num<<endl;
conductor = conductor -> link;
cout<<endl;
}
}
};
int main ()
{
list::node* base= NULL;
list object;
base = object.push_front(base,6," Lay on the ground quite still ");
base = object.push_front(base,4," Find fresh underpants to try on ");
base = object.push_front(base,8," Keep like that day after day ");
base = object.push_front(base,2," If you're attacked by a Lion ");
base = object.push_front(base,7," Pretend you are very ill ");
base = object.push_front(base,9," Perhaps the lion will go away ");
object.push_back (base,11," that boy stood on the burning deck ");
object.push_back(base,12, " a wolly scarf around his neck ");
object.push_back(base,13, " hat on his head ");
object.push_back(base,14," shoes on his feet ");
object.push_back(base,15, " he wished he was wearing trunks instead ");
object.displaylist (base);
return 0;
}
|