假设以带头结点的循环链表表示队列,并且只设一个指针指向队尾结点,但不设头指针,请写出相应的入队列算法(用函数实现)。
void EnQueue(LinkList rear, int e){
LinkList *s = (LinkList*)malloc(sizeof(LinkList));
s -> data = e;
s -> next = rear -> next;
rear -> next = s;
rear = s;
}
void add(Lnode* rear, Eletype x) { Lnode *t; t = (Lnode*)malloc(sizeof(Lnode)); if(!t) return ; t -> data = x; t -> next = rear -> next; rear -> next = t; rear = t; }
void EnQueue(queue* rear, ElemType x){ auto s = new node(x); if(!s) return; s->next = rear->next; rear->next = s; rear = s; return; }
EnQueue(LNode * L,int data){
LNode *node=(LNode*)malloc(sizeof(LNode));
LNode *p=L->next;
while(p!=L){
p=p->next
node->data=data;
node->next=r->next;
r->next=node;
r=node;
void EnQueue(Lnode *rear, ElemType e)
{ Lnode *new;
New=(Lnode *)malloc(sizeof(Lnode));
If(!new) return ERROR;
new->data=e; new->next=rear->next;
rear->next=new; rear =new;
void AddNode(LinkList &L,LNode* &n){ n->next=L->next; L->next=n; L=n; return ; }
void Enqueue(Queue* Q, int value) { Node* newNode = (Node*)malloc(sizeof(Node)); newNode->data = value; if (Q->rear == NULL) { // 如果队列为空,将新节点作为队列的第一个节点 Q->rear = newNode; newNode->next = newNode; // 自循环 } else { // 队列不为空,将新节点插入到队尾后面 newNode->next = Q->rear->next; Q->rear->next = newNode; Q->rear = newNode; // 更新队尾指针 } }
a
void EnQueue(Lnode* rear, ElemType e) { Lnode* new; new = (Lnode*)malloc(sizeof(Lnode)); if (!new) return ERROR; new->data = e; new->next = rear->next; rear->next = new; rear = new; }
typedef struct QueueNode{
int data;
struct QueueNode *next;
struct QueueNode *rear;
}QueueNode,*Queue;
void EnQueue(Queue &L, int x){
LNode *p=(QueueNode *)malloc(sizeof(QueueNode));
p->data=x;
p->next=L->rear->next;
L->rear->next=p;
L->rear=p;
struct Lnode{ ElemType data; Lnode *next; }; void add(Lnode *l,ElemType x){ Lnode * p = (Lnode *)malloc(sizeof(Lnode)); p->data = x; p->next = l->next; l->next = p; }
缘小遇 回复 Austin00: 你的尾指针好像没更改
void EnQueue(LinkQueue *Q, DataType e) { QueueNode *p = (QueueNode*)malloc(sizeof(QueueNode)); p->next = Q->rear->next; p->data = e; Q->rear = p; }
void EnterQueue(QueueNode*q int val)
{
QueueNode *p=(QueueNode*)malloc(sizeof(QueueNode));
p->data=val;
p->next=q->next;
q->next=p;
q=p;
void EnQueue(ListNode *rear,Elemtype val){
LisNode *newNode = (ListNode)malloc(sizeof(ListNode));
if(!newNode){
return Eorror;}
else{
newNode->data=val;
newNode->next=rear->next;
rear->next=newNode;
rear=newNode;
void enQueue(Queue *Q, Elemtype x){
linknode *s=(linknode *)malloc(sizeof(linknode));
s->data = x;
if(Q->rear == Null){
Q->rear = s;
s->next = s;
s->next = Q->rear->next;
void (List L,int e)
Lnode *p=new Lnode;
p->data=e;
p->next=L->next->next;
L->next=p;
void EnQueue(Lnode *rear, ElemType e){
Lnode *new;
new=(Lnode *)malloc(sizeof(Lnode));
if(!new) return ERROR;
void push(CirQueue &s,int i){
if(rear->next==L->next){ LNode *p=(LNode*)malloc(sizeof(LNode)); rear->data=i; rear->next=p; p->next=L->next; rear=p; }else{ s.rear->data=i; s.rear=s.rear->next; } }
t-yyan 回复 姜明坦: 回答的什么b东西啊
void enQueue(Queue * qList,int value){
LNode * node;
node->data=value;
node->next=qList->rear->next;
qList->rear=node;
qList-rear=qList->rear;
iheanu_ 回复 Nirvana-T: 标准的正确,经典的满分
void EnQueue(Link *rear,ElemType e){
Link *p = (Link*)malloc(sizeof(Link));
if(!p)
return ERROR;
p->next=rear->next;
rear->next=p;
rear=p;
void EnQueue(LinkQueue &Q, ElemType e){
LinkNode *s = (LinkNode *)malloc(sizeof(LinkNode));
s->data = e;
s->next = NULL;
Q.rear->next = s;
Q.rear = s;
p.next = tail.next;
tail.next = p;
tail = p;
void inQuery(Lnode *rear, Ele x) { Lnode *new = (Lnode *)malloc(sizeof(Lnode)); new->data = x; new->next = rear->next; rear->next = new; rear = new; }
答案:void EnQueue(L...
用户登录可进行刷题及查看答案
答案:void EnQueue(Lnode *rear, ElemType e)
登录后提交答案