linkedlistinsert.cpp

来自「Data Abstraction & Problem Solving with 」· C++ 代码 · 共 26 行

CPP
26
字号
#include "ListException.h"#include <iostream>using namespace std;typedef desired-item-type ItemType;struct Node{  ItemType item;   Node *next;}; // end structvoid linkedListInsert(Node *& headPtr,                      ListItemType newItem){   if ((headPtr == NULL) || (newItem < headPtr->item))   {  // base case: insert newItem at beginning      // of the linked list to which headPtr points      Node *newPtr = new Node;      newPtr->item = newItem;      newPtr->next = headPtr;      headPtr = newPtr;   }   else      linkedListInsert(headPtr->next,newItem);}  // end linkedListInsert

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?