我已经创建了节点(car)所需的数据。
struct data {
char carReg[10];
char make[20], model[20], colour[20];
int numPrevOwners;
bool reserved;
float reserveAmount;
};
我还为节点创建了模板,并声明了全局变量。
struct node {
struct data *element;
struct node *next;
};
struct node *front = NULL;
struct node *last = NULL;
在我的viewSpecific()方法中,我希望用户输入一个唯一的careg,然后它将找到存储该careg的节点并显示它。
这是我目前为止写的:
void viewSpecific() {
char result[10];
printf("Please enter the registration of the car yiew wish to view.");
scanf("%s", &result);
struct node *current, *previous;
bool notFound = true;
printf("n");
if (isEmpty())
printf("Error - there are no nodes in the listn");
else {
我不知道以后该怎么办
检查用户输入的carg是否与当前节点的carg相同。如果不是,则前进到下一个节点。如果您到达列表的末尾,那是因为没有找到carg。
/* basically, something like */
current = front;
while (current != NULL) {
if (strcmp(current->element->carReg, userCarReg) == 0) /* found */ break;
current = current->next;
}
if (current == NULL) {
printf("carReg not foundn");
} else {
printf("carReg: %sn", current->element->carReg);
printf("make: %sn", current->element->make);
printf("previous owners: %dn", current->element->numPrevOwners);
}