Basic Data Structures

Source: Internet
Author: User

Stack-empty (S)
If s.top = = 0
Return TRUE
else return FALSE

PUSH (s,x)
S.top = s.top + 1
S[s.top] = X

POP (S)
If Stack-empty (S)
Error "Underflow"
else S.top = s.top-1
return s[s.top+1]

Queue
INSERT, ENQUEUE
DELETE, DEQUEUE

ENQUEUE (q,x)
Q[q.tail]=x
if Q.tail = = Q.length
Q.tail = 1
else Q.tail = q.tail + 1

DEQUEUE (q.x)
x = Q[q.head]
if (Q.head = = q.length)
Q.head = 1
else Q.head = q.head + 1
return x

Linked list, doubly linked list, unidirectional linked list, circular link list
List-search (L,k)
x = L.head
While x! = NULL and X.key! = k
x = X.next
return x

List-insert (l,x)
X.next = L.head
If l.head! = NIL
L.head.prev = X
L.head = X
X.prev = NIL

List-delete (l,x)
If X.prev! = NIL
X.prev.next = X.next
else L.head = X.next
If X.next! = NIL
X.next.prev = X.prev

Sentinel
List-search (L, K)
x = L.nil.next
While x! = L.nil and X.key! = k
x = X.next
return x

List-insert (l,x)
X.next = L.nil.next
L.nil.next.prev = X
L.nil.next = X
X.prev = L.nil

Pointers and Object implementations

Objects and most groups represent

object and singular group representations

Allocation and release of objects

Suppose that the array length in most group notation is M, and the dynamic collection contains n<=m elements at a given moment. n objects represent the existing dynamic
The elements in the collection, while the remaining M-n objects are free, and these free objects can be used to represent the elements to be inserted into the dynamic collection

Free Form
Allocate-object ()
If free = NIL
Error "Out of space"
else x = Free
Free = Free.next
return x

Free-object (x)
X.next = Free
Free = X

Multi-linked list majority group notation



Basic Data Structures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.