Follow

Translate

Sunday, March 20, 2016

Inserting at the Beginning of a List


Algorithm:   INSFIRST(INFO,  LINK,  START, AVAIL, ITEM)


1.     [OVERFLOW?]  If AVAIL = NULL , then : Write: OVERFLOW, and Exit.

2.   [Remove first node from AVAIL list. ]

   Set NEW : = AVAIL and AVAIL : = LINK[AVAIL].

3.  Set INFO[NEW] : = ITEM.  [Copies new data into new node]

4.  Set LINK[NEW] : = START.      [New node now points to original first node.]

5.  Set START : = NEW.     [Changes START so it points to the new node]

6.  Exit
If You want to learn about the technology, computer science & engineering, web programming, freelancing, earning please click here :CSE SOLVE

Related Posts:

  • Inserting into a Sorted Linked List Inserting into a Sorted Linked List:   Suppose ITEm is to be inserted into a sorted linked LIST.  Then ITEM must be inserted between nodes A and B so that         … Read More
  • Two-Way Header Lists Two-Way Header Lists:   The advantages of a two-way list a circular header list may be combined into a two-way circular header list as .  The list is circular because the two end nodes point back to the head… Read More
  • Arithmetic Expressions;Polish Notation Arithmetic Expressions;Polish Notation :  Highest : Exponentiation Next Highest : Multiplication (*) and Division(/) Lowest : Addition(+) and Subtruction(-) If You want to learn about the technology, compu… Read More
  • Deletion Algorithms Deletion Algorithms: Algorithms which delete nodes from linked lists come up in various situations. We discuss two of them here. The first one deletes the node following a given node, and the second one deletes the node wi… Read More
  • COPY(INFO, LINK, NAME1, NAME2, AVAIL) COPY(INFO, LINK, NAME1, NAME2, AVAIL) This algorithm makes a copy of a list NAME1 using NAME2 as the list pointer variable of the new list. 1.     Set NAME2 : = NULL.   [Forms empty  … Read More

0 comments:

Post a Comment