c++ 读取访问权限冲突。
#include <stdio.h>
#include <stdlib.h>
#include "stdafx.h"
using namespace std;
typedef struct Node
{
int m_nValue;
Node *m_pNext;
}ListNode;
ListNode * creat_List() {
ListNode *pHead;
pHead = new ListNode();
pHead->m_nValue = 0;
pHead->m_nValue = NULL;
return pHead;
}
ListNode*insert_Node_behind(ListNode*pHead, int pElem) {
if (pHead = NULL) {
cout << "头结点为空" << endl;
return pHead;
}
ListNode *temp, *current;
current = pHead;
while (current->m_pNext)
{
current = current->m_pNext;
}
temp = new ListNode();
temp->m_nValue = pElem;
temp->m_pNext = NULL;
current->m_nValue += 1;
return pHead;
}
void show_List(ListNode *pHead)
{
if (pHead==NULL)
{
cout << "头结点为空" << endl;
return;
}
ListNode *temp;
temp = pHead->m_pNext;
cout << "该list为:";
while (temp!=NULL)
{
cout << temp->m_nValue << ' ';
temp = temp->m_pNext;
}
cout << endl;
}
ListNode *reverse_list_1(ListNode *pHead) {
if (pHead==NULL||NULL==pHead->m_pNext)
{
return pHead;
}
ListNode *temp, *current;
current = pHead->m_pNext;
pHead->m_pNext = NULL;
while (current!=NULL)
{
temp = current->m_pNext;
current->m_pNext = pHead->m_pNext;
pHead->m_pNext = current;
current = temp;
}
return pHead;
}
int main()
{
int n_of_list = 6;
int i = 1;
ListNode *pHead;
pHead = creat_List();
while (n_of_list>0)
{
insert_Node_behind(pHead, i++);
n_of_list;
}
show_List(pHead);
reverse_list_1(pHead);
show_List(pHead);
return 0;
}