ZKX's LAB

在n个结点的顺序表中,算法的时间复杂度是O(1)的操作是: 辅助接点单链空开接法

2020-07-20知识7

对于双向链表,在两个结点之间插入一个新结点需修改的指针共( )个,单链表为( )个. 4,2在双向链表的结点A和B之间插入结点P需要修改:P的前驱,P的后继,A的后继,B的前驱在单向链表的结点A和B之间插入结点P需要修改:P的后继,A的后继二叉排序树中插入一个结点的时间复杂度是多少 最差情况下是O(n)如果是最一般最基础的二叉树的话,因为深度不平衡,所以会发展成单链的形状,就是一条线 n个点那么深如果是深度平衡的二叉树 o(logn)在带头结点的双向循环链表中插入一个新的结点,需要修改的指针域数量是多少 一般双向链表节点定义 struct node{struct node*prev;struct node*next};插入一个新节点,struct node*newnode;该新节点的prev要指向前面一个节点,next指向后面一个节点,。怎样在单链表L中查找第n个接点?(我需要完整的程序:越详细越好) #include<;iostream>;#include<;conio.h>;#include<;iomanip>;#include\"other.h\"using namespace std;struct L { int num;节点编号 int index;节点索引 L*Next;当前节点的下一节点 };void UpdateIndex(L*beginPoint,int index){ while(beginPoint){ beginPoint->;index=index;beginPoint=beginPoint->;Next;index+;} } L*Delete(L*Head,int num){ if(Head){ L*dealPoint;if(Head->;num=num){ dealPoint=Head;Head=Head->;Next;更新当前节点的下级节点的索引 if(dealPoint->;Next){/用要删除节点的索引来更新下一节点的索引 UpdateIndex(dealPoint->;Next,dealPoint->;index);} delete dealPoint;return Head;} for(L*P=Head;P->;Next;P=P->;Next){ if(P->;Next->;num=num){ dealPoint=P->;Next;P->;Next=dealPoint->;Next;更新当前节点的下级节点的索引 if(dealPoint->;Next){ UpdateIndex(dealPoint->;Next,dealPoint->;index);} delete dealPoint;break;} } } return Head;}/查找指定第几个节点 L*FindPoint(L*Head,int index){ if(Head){ L*findPoint;for(L*P=Head;P->;Next;P=P->;Next){ if(P->;index=index){ findPoint=P;break;} } return findPoint;} else { return NULL;} }/创建连表 L*。1.在循环双向链表中在指针p所指结点前插入一个结点*s的语句,空格处怎么填啊?求大神, s->;next=p;s->;prior=p->;prior;p->;prior->;next=s;p->;prior=s;链表中插入一个节点 帮忙分析一下 下面是程序的一部分,p为指向要插入的节点,链表不为空 node*insert(node*head,node p) { node*p1,*p2;if(head->;data>;=p->;data){ p->;next=head;。2. 假设以带头结点的循环链表表示队列,并且只设一个指针指向队尾元素结点而不设 #includeincludeincludedefine OK 1define ERROR 0define OVERFLOW 0typedef struct N0de{int data;struct N0de*next;}N0de,*QueuePtr;typedef struct{QueuePtr rear;}LinkQueue;int InintQueue(LinkQueue&Q){ Q.rear=(QueuePtr)malloc(sizeof(N0de));if。Q.rear)return(OVERFLOW);Q.rear->;next=Q.rear;return OK;}int EnQueue(LinkQueue&Q,int e){QueuePtr p;p=(QueuePtr)malloc(sizeof(N0de));p->;data=e;p->;next=Q.rear->;next;Q.rear->;next=p;Q.rear=p;return OK;}int DeQueue(LinkQueue&Q,int&e){ QueuePtr p;if(Q.rear->;next=Q.rear)return 0;p=Q.rear->;next->;next;e=p->;data;Q.rear->;next->;next=p->;next;if(Q.rear=p){Q.rear->;next=Q.rear->;next->;next;Q.rear=Q.rear->;next;}free(p);return OK;}void main(){LinkQueue Q;int i,e,n;InintQueue(Q);printf(\"input the number of the data:\");scanf(\"%d\",&n);for(i=0;i;i+){printf(\"enter the queue:\");scanf(\"%d\",&e);EnQueue(Q,e);}printf(\"input the number of the datas to out:\");scanf(\"%d\",&n);for(i=0;i;i+){printf(\"output first data in the queue:\");DeQueue(Q,e);printf(\"%d\\n\",。

#next#查找算法#printf#链表

随机阅读

qrcode
访问手机版