在C++链接列表中帮助.show记录功能启动无限循环
In C++ Link list help ..show Record function started infinite loop
我编写了一个程序,在其中实现了linklist(structure),有两个函数setRecord
用于获取用户的ID,第二个函数是显示ShowRecord()
但是当我输入 ID 然后想显示记录时..它只显示第一个和最后一个节点或...现在进行了一些更改,它以最后一个ID开始无限循环...代码如下...
// linklist practice.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
using namespace std;
struct info
{
int data;
info *next;
};
void setRecord(info *temp);
void showRecord(info *temp);
int main()
{
char a;
info *base = new info;
info *temp;
info *last;
temp = base;
last = base;
setRecord(temp);
//do
// {
do
{
info *std = new info;
std = last;
temp->next = std;
//std->next = NULL;
setRecord(temp);
temp->next = temp;
cout << "Do you wanna Enter another....?(y or n):n";
cin >> a;
} while (a =='y');
// break;
//} while (1);
last = NULL;
showRecord(temp);
system("pause");
system("pause");
return 0;
}
void setRecord(info *temp)
{
cout << "Enter your ID:->";
cin >> temp->data;
}
void showRecord(info *temp)
{
while (temp != NULL)
{
cout << "ID number "<< temp->data;
cout << endl;
temp = temp->next;
}
}
更改main()
方法。
int main()
{
char a;
info *base = new info;
info *temp;
info *first;
temp = base;
first=temp;
setRecord(temp);
//do
// {
do
{
info *std = new info;
temp->next = std;
//std->next = NULL;
temp=std;
setRecord(temp);
temp->next = null;
cout << "Do you wanna Enter another....?(y or n):n";
cin >> a;
} while (a =='y');
// break;
//} while (1);
showRecord(first);
system("pause");
system("pause");
return 0;
}
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 多态性和功能结合
- 带内存和隔离功能的SQLite
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- 类模板的成员功能的定义在单独的TU中完全专业化
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 将两个数组中的差异记录在第三个数组中
- 如何在C++中获得"静态纯虚拟"功能?
- 如何记录C++20模块中的功能
- 列出当前过程并使用未记录的当前功能编写内存的软件技巧
- Log4Cplus - 更改级别以记录在不同的功能中
- 具有进程间通信功能的服务器-客户端日志记录体系结构.你知道解决方案吗?
- 苹果记录器(ASL)忽略/etc/ASL.conf中的规则以获得特定的功能
- C/C++日志记录功能,支持根据日志级别进行的条件函数调用
- 如何确保信号到达记录仪功能
- 使用操作员<<的记录功能
- 如何用氧气记录SFINAE启用的功能
- 如何用氧气记录朋友注射功能
- 如何在项目中实现良好的调试/日志记录功能
- 在C++链接列表中帮助.show记录功能启动无限循环