#include "stdafx.h"
#define sub(a,b) a-b //没用
#include
using namespace std;
struct node
{
int a;
node * next;
};
int _tmain(int argc, _TCHAR* argv[])
{
//int x=sub(3,8);
node * createList();
cout<
node *pbeg=createList();
node *p=pbeg;
while (p)
{
cout<a<
p=p->next;
}
cout<
int loc;
cin>>loc;
node * delEle(node * pbeg,int loc);
node * ru;
ru=delEle(pbeg,loc);
cout<
while (ru)
{
cout<a<
ru=ru->next;
}
node * rt(node * pbeg);//声明函数
node * r=rt(pbeg);
cout<
while (r)
{
cout<a<
r=r->next;
}
return 0;
}
//使单链表变为原来的逆序
node * rt(node * pbeg)
{
node * pPre=pbeg;
node * pCur=pPre->next;
node * pNext=NULL;
while(pCur)
{
pNext=pCur->next;
pCur->next=pPre;
pPre=pCur;
pCur=pNext;
}
pbeg->next=NULL;
return pPre;//返回新的表头节点
}
//创建单链表
node * createList()
{
node * pbeg=new node;
(*pbeg).a=1;
node * p=pbeg;
int j=9;
node * q;
while(j>0)
{
j--;
q=new node;
cout<
int temp;
cin>>temp;
q->a=temp; //赋值
p->next=q;
p=q;
}
p->next=NULL;
return pbeg;
}
//删除指定元素的节点;
node * delEle(node * pbeg,int ele)
{
node * pPre=pbeg;
node *pCur=pbeg->next;
if (pbeg->a==ele)
pbeg=pbeg->next;
else
{
while (pCur->a!=ele&&pCur)
{
pPre=pCur;
pCur=pCur->next;
}
pPre->next=pCur->next;
}
return pbeg;
}