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:

  • Arrays, Records and Pointers Arrays, Records and Pointers  The Operation one normally performs on any linear structure. (a) Traversal: Processing each element in the list. (b) Search: Finding the location of the element with a given value or the… Read More
  • Linear Search Algorithm 2.4 Linear Search Algorithm 2.4: (Linear Search) A Linear Array DATA with N elements and a specific ITEM of information are given. This algorithm finds the location LOC of ITEM in the array DATA or sets LOC = 0. 1.  [Ini… Read More
  • Algorithm Largest Element in Array Algorithm 2.1: (Largest Element in Array) A nonempty array DATA with N numerical values is given.This algorithm finds the location LOC and the value MAX of the largest element of DATA.The variable K is used as a counter. St… Read More
  • Traversing Linear Arrays Algorithm 4.1: (Traversing a Linear Array) Here LA is a linear array with lower bound LB and upper bound UB. This algorithm traverses LA applying an operation Process to each element of LA. 1. [Initialize counter.] Set K :… Read More
  • Complexity Of Algorithms Complexity Of Algorithms: There are two case for describing in the complexity of algorithms: (1) Worst Case: The Maximum value of f(n) for any possible input. (2) Average Case: The expected value of f(n) Sometimes we al… Read More

0 comments:

Post a Comment