是程序题~高手们帮忙看下哈~谢谢啦

来源:百度知道 编辑:UC知道 时间:2024/06/02 21:10:35
下面是一个单链表的类声明,请实现各类中所有未实现的成员函数。并编写有关栈操作
的测试程序。
class node{
friend class llist;
private:
node *next;
char *contents; // contents dynamically allocated
};
class list {
private:
node *head; // head of list
int size; // number of bytes for contents
public:
list(int s) { head=0; size=s; }
void insert (char *a); // add to the front of the list
char *get(void); // remove the head of the list
void clear(void); // remove all the nodes in list
~ list (void) { clear(); }
};
然后从list类派生整数栈:
class int_stack: public list {
public:
void push(int a);
int pop(void);
int_stack();
~int_stack(); };

#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
class node{
friend class list;
private:
node *next;
char *contents; // contents dynamically allocated内容动态分配
};
class list{
private:
node *head; // head of list
int size; // number of bytes for contents
public:
list(int s) { head=0; size=s; }
void outputlist();//output
void insert (char *a); // add to the front of the list
char *get(void); // remove the head of the list
void clear(void); // remove all the nodes in list
~ list (void) { clear(); }
};
void list::outputlist()
{
node *p=head;
if(p!=NULL)
{
cout<<"栈中内容为:";
while(p!=NULL)
{
cout<<p->contents<<" ";
p=p->next;