//头插法#include using namespace std;#include struct ListNode {int data;ListNode* next;};ListNode * CreateListNode(ListNode *L) {int a;cin>>a;while(a!=0) {ListNode *p = new ListNode;p->data = a;p->next = L->next;L->next = p;cin>>a;}cout<<"end"<next) {cout <next->data<next;}}int main(int argc, const char * argv[]) {//设置头节点ListNode *L = new ListNode;//将头节点的指针域置空L->next = NULL;CreateListNode(L);display(L);}