Show Menu
Cheatography

Queue Stack Linked List Cheat Sheet by

Pseudo codes for all these

QUEUE

peek()
begin procedure peek()
return queue[­front]
end procedure

int peek(){
return queue[­front]
}

QUEUE

isEmpty()
begin procedure isEmpty()
if(fro­nt<MIN || front>­rear)
return true
else
return false
endif
end procedure
OR
bool isEmpty() {
if(fro­nt<­0||­fro­nt>­rear)
return true
else
return false

QUEUE

isFull
begin procedure isFull()
if(rea­r==­MAX­_SI­ZE-1)
return true
else
return false
endif
end procedure
OR
bool(i­sFu­ll()) {
if(rea­r==­MAX­_SIZE -1){
return true
else
return false}

QUEUE

enqueue
procedure enqueu­e(data)
if queue is full
return overflow
endif
rear<-­rear+1
queue[­rea­r]<­-data
return true
end procedure
OR
if enqueu­e(int data)
if(isF­ull())
return 0;
rear=r­ear+1;
queue[­rea­r]=­data;
return 1;

QUEUE

dequeue
procedure dequeue
if queue is empty
return underflow
endif
data=q­ueu­e[f­ront]
front<­-fr­ont+1
return true
end procedure
OR
int dequeue() {
if(isE­mpty())
return 0;
int data;
data=q­ueu­e[f­ront];
front=­fro­nt++;
return data;
 

SINGLY LINKED LIST

Initia­liz­ation
struct node
{
int data;
}
struct node *next;
struct node * head = null,
struct node *newnode;
newnod­e=(­struct node*)­mal­loc­(si­zeo­f(s­truct node))
newnod­e->­dat­a=data;
newnod­e->­nex­t=null

SINGLY LINKED LIST

Insert at front
//inse­rtf­ron­t(h­ead,x)
{
newnod­e=c­reate newnode
newnod­e->­dat­a=data
newnod­e->­nex­t=null
if(hea­d!=­null)
newnod­e->­nex­t=head
head=n­ewnode
end

SINGLY LINKED LIST

Insert at end
//inse­rte­nd(­tem­p,head)
{
newnod­e->­nex­t=null
temp=head
while(­tem­p->­nex­t!=­null) do
temp=t­emp­->next
end while
temp->­nex­t=n­ewnode
newnod­e->­nex­t=null
}

SINGLY LINKED LIST

Insert at any position
//inse­rta­tan­ypo­s(h­ead­,x,pos)
{
temp=head
while(­i<pos)
temp=t­emp­->next
i++
endwhile
newnod­e=c­reate newnode
newnod­e->­dat­a=data
newnod­e->­nex­t=t­emp­->next
temp->­nex­t=n­ewnode
}

SINGLY LINKED LIST

Delete from last
//dele­tel­ast­(he­ad,­tem­p,ptr)
{
if(hea­d->­nex­t=null)
temp=head
head=null
else
temp=head
while(­tem­p->­nex­t!=­null)
ptr=temp
temp=t­emp­->next
ptr->n­ext­=null
free(temp)
}

CIRCULAR QUEUE

enqueue
begin
if(fro­nt=­=(r­ear­+1)­%MAX)
print queue is full
else read x
if(fro­nt==-1)
front=­rear=0;
else
rear=(­fro­nt+­1)%MAX
queue[­rear]=x
endif
end enqueue
 

DOUBLE LINKED LIST

Delete from front
if(hea­d==­null)
underflow
set ptr=head
head=h­ead­->next
head->­pre­v=null
free(ptr)
exit

DOUBLE LINKED LIST

Delete from last
if(hea­d==­null)
underflow
else
set temp=head
repeat while (temp-­>ne­xt!­=null){
temp=t­emp­->next
}
temp->­pre­v->­nex­t=null
free(temp)
exit

DOUBLE LINKED LIST

Delete from any position
if(hea­d==­null)
underflow
else
temp=head
repeat while(­tem­p->­dat­a=i­tem){
temp=t­emp­->next
}
if(tem­p->­nex­t==­null)
return
else
ptr=te­mp-­>next
temp->­nex­t=p­tr-­>next
ptr->n­ext­->p­rev­=temp
free(ptr)
exit

SINGLY LINKED LIST

Delete from any position
//dele­tea­ny(­hea­d,x­,pos)
{
i=0
temp=head
while(­i<pos) {
ptr=temp
temp=t­emp­->next
i++}
ptr->n­ext­=te­mp-­>next
free(temp)
}

SINGLY LINKED LIST

Delete from front
//dele­tef­ron­t(h­ead­,temp)
{
if(hea­d==­null)
no list
else
temp=head
head=h­ead­->next
free(temp)
}
 

DOUBLE LINKED LIST

Initia­liz­ation
struct node
{
struct node *prev
int data
struct node *next
}
struct node *head

DOUBLE LINKED LIST

Insert at front
if(hea­d==­null) do
newnod­e->­nex­t=null
newnod­e->­pre­v=null
newnod­e->­dat­a=item
head=n­ewnode
else
newnod­e->­nex­t=head
head->­pre­v=n­ewnode
newnod­e->­pre­v=null
head=n­ewnode

DOUBLE LINKED LIST

Insert at end
temp=head
while(­tem­p!=­null)
{
temp=t­emp­->next
}
temp->­nex­t=n­ewnode
newnod­e->­pre­v=temp
newnod­e->­nex­t=null

DOUBLE LINKED LIST

Insert at any position
temp=head
for(i=­0;i­<lo­c;i++)
{
temp=t­emp­->next
if(tem­p==­null)
{
return
}}
ptr->n­ext­=te­mp-­>next
ptr->p­rev­=temp
temp->­nex­t=ptr
ptr->n­ext­->p­rev=ptr

CIRCULAR QUEUE

Initia­liz­ation & Display
queue()
begin
front=­rear=-1
repeat for i=0 to MAX-1
queue[i]=0
end
AND
Disp()
begin
for i=0 to MAX-1 do
write que[i]
end for
end disp

CIRCULAR QUEUE

dequeue
begin
if(fro­nt==-1)
then write "­queue is empty"
else
write "­element dequeued is %d",­que­ue[­front]
queue[­fro­nt]=0
if(fro­nt=­=rear)
front=­rear=-1
else
front=­(fr­ont­+1)%MAX
end dequeue
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          HTTP Status Codes Cheat Sheet
          Mercurial (Hg) Cheat Sheet
          Pseudocode Cheat Sheet