数据结构 单链表基本操作代码

实验一 单链表#include "stdio.h"#include "stdlib.h"typedef int ElemType;typedef struct LNode{ ElemType data

实验一单链表 #include"stdio.h" #include"stdlib.h" typedefintElemType; typedefstructLNode { ElemTypedata; structLNode*next; }LNode,*LinkList; voidcreatLNode(LinkList&head) { inti,n; LNode*p; head=(LNode*)malloc(sizeof(LNode)); head->next=NULL; printf(""); 请输入链表的元素个数: scanf("%d",&n); for(i=n;i>0;i--) { p=(LNode*)malloc(sizeof(LNode)); printf("%d",i); 第个元素: scanf("%d",&p->data); p->next=head->next; head->next=p; } } voidInsertLNode(LinkList&L) { LNode*p=L; inti,j=0,e; printf(""); 请输入你要插入的位置(超过链表长度的默认插在最后!): scanf("%d",&i); printf(""); 请输入你要插入的元素: scanf("%d",&e); while(p->next&&j<i-1) { p=p->next; ++j; }

腾讯文库数据结构