#include运行:#include using namespace std;typedef struct Node{ char c; struct Node *next;}*LinkList,LNode;//初始化单链表hLinkList Init(LinkList &h){ h=(LNode*)malloc(sizeof(LNode)); if(h==NULL) { cout<<"没有足够的内存空间"< next=NULL; return h;}//尾差法插入元素void InsertNum(LinkList &h,int n){ LinkList r,s; r=h; for(int i=0;i next=s; cin>>s->c; r=s; } r->next=NULL;}//输出单链表hvoid outputLinkList(LinkList h){ LinkList p=h->next; while(p!=NULL) { cout< c<<" "; p=p->next; }}//求单链表h的长度int GetLength(LinkList h){ LinkList p; p=h->next; int count=0; while(p!=NULL) { count++; p=p->next; } return count;}//输出单链表的长度void outputListLength(LinkList h){ cout<<"当前链表的长度为: "< < next==NULL) cout<<"该链表为空!"< curLen) { cout<<"位置输入错误!"< next; for(int i=1;i next; } cout<<"该链表的第"< <<"个元素为: "< c< next; int position=1; while(p!=NULL) { if(p->c==a) { cout<<"元素"< <<"在链表中的位置为 :"< < <<"在链表中不存在!"<next; position++; } if(position-GetLength(h)>1) cout<<"元素"< len) { cout<<"位置错误,不能插入!"< next; LinkList temp; temp=(LNode*)malloc(sizeof(LNode)); if(n==1) { temp->next=p; h->next=temp; temp->c=a; } else { for(int i=2;i next; } temp->next=p->next;//3 p->next=temp; temp->c=a; } }}//删除链表的第n个元素void deleteNthNum(LinkList &h,int n){ if(n<=0||n>GetLength(h)) { cout<<"删除位置输入错误!"< next; } q=p->next; p->next=q->next; free(q); }}//释放链表void freeList(LinkList &h){ free(h);}int main(){ LinkList h; cout<<"欢迎进入单链表操作程序,本程序提供以下操作:"< >op&&op) { switch(op) { case 2: { int n; cout<<"输入n的值:";cin>>n; cout<<"输入插入的n个数的值:"; InsertNum(h,n); cout<<"插入成功!"< >n; outputNthNum(h,n);break; } case 6: { char a; cout<<"输入a的值:";cin>>a; outputNumPosition(h,a);break; } case 7: { Empty(h);break; } case 8: { int n;char f; cout<<"输入n的值: ";cin>>n; cout<<"输入f的值: ";cin>>f; InsertNumOnth(h,n,f); cout<<"插入成功!"< >n; deleteNthNum(h,n); cout<<"删除成功!"<