1)创建一个新的结点,并使指针p指向该节点 2)输入该结点的数据域,即p->data 3)将p的指针域置空并将r的指针域指向结点p 4)让指针p指向r(保证指针r指向该链表的最后一个结点) 算法描述: void CreatList_H(LinkList &L,int n) { L=new LNode; L->next=NULL; r=L; for(i=0;i<n;i...
单链表的插入 尾插法:使用一个临时结点直接找到最后一个结点 temptemp,然后 temp.next=newNode,newNode.next=nulltemp.next=newNode,newNode.next=null 在中间结点插入一个结点:找到要插入结点的位置的前一个位置的结点 temptemp,让待插入结点的 nextnext 域指向 temptemp 的后面的结点,最后让 ...
单链表的初始化,创建,插入,删除和反转 1#include<stdio.h>2#include<stdlib.h>34typedefintElemtype;5typedefstructNode6{7Elemtype data;8structNode *next;9}Node, *LinkedList;1011//单链表的初始化12LinkedList LinkedListInit()13{14Node *L;15L = (Node*)malloc(sizeof(Node));16if(L ==NULL)17{18...
Insert(struct student *head,int Num) /*head为链表头指针,Num插入链表位置*/ { int t=1; struct student *p1,*p2; p1=head; if (Num>n||Num<0) { printf("input error!!!\n"); return 0; } while(t<Num-1) /*找到要插入结点的前一个结点*/ { p1=p1->Next; t++; } p2=(struct st...
cout<<"请输入一串单字符数据,以*结束!"<<endl;char ch;link *HEAD;link *R,*P,*L;HEAD=(link *)malloc(sizeof(link));HEAD->next=NULL;R=HEAD;getchar();ch=getchar();while(ch!='*'){ P=(link *)malloc(sizeof(link));P->data=ch;P->next=NULL;R->next=P;R=R->next...
{int data;struct node *next;}node;node * createsl(){ node *p,*s,*h;int j=1,x;p=s=h=(node*)malloc(sizeof(node));h->next=NULL;printf("please input the data to create the list,end with -1 or %d nupmbers\n",N);while(x!=-1&&j<=N){ printf("number %d:",j...
单链表的创建和插入删除操作 1#include<stdio.h>//单链表的定义和基本操作2#include<stdlib.h>//malloc函数所需要的头文件3#include<stddef.h>//定义NULLL的头文件45typedefstructLNode//定义单链表的节点6{7intdata;8structLNode*next;9}LNode;1011voidCreatlinklist(LNode *&L,inta[],intn)//尾插法...