|
查看: 958|回复: 1
|
帮帮忙!C++问题
[复制链接]
|
|
|
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <fstream.h>
using namespace std;
class nodeStack
{
public :
string name,ID,type;
nodeStack * next;
};
class stack
{
private:
nodeStack * Top;
public:
void create();
void push(string a, string b, string c);
nodeStack* pop();
string stackTop();
bool isEmpty();
nodeStack* search(string a, nodeStack* data);
};
void stack::create()
{
Top = NULL;
}
bool stack::isEmpty()
{
return bool (Top == NULL);
}
void stack::push(string a, string b, string c)
{
nodeStack* newnode;
newnode->name = a;
newnode->ID = b;
newnode->type = c;
newnode->next = Top;
Top = newnode;
}
nodeStack* stack::pop()
{
nodeStack* node;
node = Top;
Top = Top->next;
return node;
}
nodeStack* stack::search(string a, nodeStack* data)
{
if ( a == data->ID)
{ return data; }
}
int main()
{
stack list;
int num = 1;
string a, b, c,srh;
nodeStack* newnode;
nodeStack* newdata;
nodeStack* searchnode;
list.create();
ifstream input ("abac.txt");
for (int i=0; i<25; i++)
{
input >> a;
input >> b;
input >> c;
list.push(a,b,c);
}
nodeStack* data[num];
for (int i=0; i
{
newnode = list.pop();
data = newnode;
}
cout<< "Please enter the ID you want to search for :";
cin >>srh;
for(int i=0; i
{
data = newdata;
searchnode = list.search(srh,newdata);
}
cout<<"Name :"<name<<<"ID :"<ID<<<"Phone Type:"<type<
getch();
return 0;
}
没法run!!请那位大大来帮忙....
[ 本帖最后由 悲哀河川 于 15-10-2008 12:58 AM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 16-10-2008 12:00 AM
|
显示全部楼层
cout<<"Name :"<name<<<"ID :"<ID<<<"Phone Type:"<type<
name, id, type 从何处来? id? list.id ?
还有,
void stack::push(string a, string b, string c)
{
nodeStack* newnode;
newnode->name = a;
newnode->ID = b;
newnode->type = c;
newnode->next = Top;
Top = newnode;
}
nodeStack* newnode; ?? newnode 只是一个pointer, 她指向哪里?你要的应该是pop, 应该是
nodeStack* newnode = new notestack; 吧? |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|