我有一个实现堆栈类的通用列表类(主类),我将在下面显示主类的推送部分:(s1是生成的列表的副本通过拷贝构造函数)我的推送方法出错了,我想
for (int i=0; i<1000; i++) // push 1000 times with i+100
s1.Push(i+100);
cout << "*Push(i+100) 1000 times\ns1=" << s1 << endl;
cout << "s1.Size()=" << s1.Size() << endl;
cout << "s1.IsEmpty()=" << ((s1.IsEmpty()) ? "T" : "F") << endl;
cout << "s1.IsFull()=" << ((s1.IsFull()) ? "T" : "F") << endl;
cout << "s1.Peek()=" << s1.Peek() << endl;
cout << endl;
的方法我都推是:
`void Push(T item)
{
Node *p = new Node;
p -> data = item;
p->link = top;
top = p;
num_items++;
}`
我期待得到的输出是:
*Push(i+100) 1000 times
s1=129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100
s1.Size()=30
s1.IsEmpty()=F
s1.IsFull()=T
s1.Peek()=129
但相反,我收到了这个输出,我将在下面的图像中发布。
编辑: 当我将其更改为只推100个栈这是输出我得到的,
左边的白色预期的输出,我希望增加清晰度。
所以你说你希望在输出“109”后,一堆的空间,并没有得到它? –
您的“预期输出”模块与您张贴的图像的实际输出完全相同 –
您至少需要告诉我们's1'是什么,并且可能向我们展示它是IO方法。 '推'看起来不错(只是猜测,因为你还没有给我们,或者......) – John3136