- #include <iostream>
- using namespace std;
- /* 创建一个单链表 */
- struct ListNode{
- int m_key;
- ListNode* next;
- };
- void createList(ListNode* pHead){
- ListNode* p = pHead;
- for (int i = 1; i < 10; ++i) {
- ListNode* pNewNode = new ListNode;
- pNewNode->m_key = i; // 将新节点的值赋值为i
- pNewNode->next = NULL;
- p->next = pNewNode; // 上一个节点指向这个新建立的节点
- p = pNewNode; // p节点指向这个新的节点
- }
- }
- int main(){
- ListNode* head = NULL;
- head = new ListNode;
- head->m_key = 0;
- head->next = NULL;
- createList(head);
- system("pause");
- return 0;
- }
C++学习 1单向链表建立(内容来自chixujohnny)
猜你喜欢
转载自blog.csdn.net/sannianyihoushuma/article/details/79749316
今日推荐
周排行