求助 链表
求助链表 救命啊 ???#include <iostream>
using std::cin;
using std::cout;
using std::endl;
struct node
{
char ch;
node *next;
};
node *creatlist() //创建链表
{
node *beg = new node;
node *head = beg; //头结点
beg->ch = cin.get(); //读取数据
while (beg->ch != '\n')
{
beg->next = new node; //申请新节点
beg = beg->next; //指针指向新节点
beg->ch = cin.get();//读取下一个数据
}
beg->next = nullptr; //尾结点指向空节点
return head; //返回头结点
}
void printNode(node *list) //输出节点数据
{
while (list->next != nullptr) //遍历节点
{
cout << list->ch;//输出数据
list = list->next; //移动节点指针
}
}
int main(int argc, char const *argv[])
{
node *list = creatlist();
printNode(list);
return 0;
}
============================================================
Microsoft Windows [版本 10.0.18363.476]
(c) 2019 Microsoft Corporation。保留所有权利。
E:\Users\admin\Documents\VScode\Code>c:\Users\admin\.vscode\extensions\ms-vscode.cpptools-0.26.2\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-mghsc1tp.ozo --stdout=Microsoft-MIEngine-Out-sdslqt13.uig --stderr=Microsoft-MIEngine-Error-pw2tuepu.z3z --pid=Microsoft-MIEngine-Pid-3p4twawm.qjl --dbgExe=D:\MinGW\bin\gdb.exe --interpreter=mi
this is a nodelist!
this is a nodelist!
E:\Users\admin\Documents\VScode\Code>
页:
[1]