You are on page 1of 8

c

POINTER:-
A pointer is a variable that holds the address of another variable.

POINTER TO POINTER:-
Pointer-to-pointer holds address of another pointer. So it requires double
dereferencing to obtain the value object.

EXAMPLE:-
int **p;

This is a declaration of pointer to pointer for int object.


C++ allows the use of pointers that point to pointers, that these, in its turn,
point to data (or even to other pointers). In order to do that, we only need to
add an asterisk (*) for each level of reference in their declarations:
P 
P 
P 


 
 c
c
This, supposing the randomly chosen memory locations for each variable
of 7230, 8092 and 10502, could be represented as:
ccccccccc cccccccccccccccccccccccccccccccccccccccccccccccccccccccc
ccccccccccccc
Œ  ÿŒ   Œ
c

ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 
c

The value of each variable is written inside each cell; under the cells are
their respective addresses in memory.
The new thing in this example is variable c, which can be used in three
different levels of indirection, each one of them would correspond to a
different value:
 ×c cc× ccc 
c cc
 ×c cc× ccc 
c c c
 ×c cc× ccc 
c c

c

PROGRAM:-
P 

P 
P 
 
 
P  P

P    
 
P  
 
P     !

P  

P   !

P    " #

P  

P  
 

LINKED LIST:-
A linked list or one way list is a linear collection of data elements, called
nodes, where the linear order is given by means of pointers .That is each
node is divided into twocparts: the first part contains the information of the
element, and the second part, called the linked list or next pointer field,
contains the address of next node in the list.

The pointer of last node contains a special value, called the null pointer,
which is any invalid address.

0 and negative number is used for the null pointer.

EXAMPLE:-
A hospital ward contains 12 beds, of which 9 are occupied .We want an
alphabetical listing of the patients. we use variable START to point first
patient. Hence START contains 5, since the first patient, Adams, occupies
bed 5.Also Adams¶s pointer is equal to 3;Since Dean the next patient.

START ß 
    
 
    ÿ

Π 

 
 

 
  Œ

 
 

  

ÿ 
  

   

 
  

  

   

Π  

REPRESENTATION OF LINKED LIST IN MEMORY:-


LIST be a linked list. LIST requires two linear arrays, we will
call them here INFO and LINK such that INFO[K] and LINK[K] contain,
respectively, the information part and the nextpointer field of a node of
LIST.LIST also requires a variable name such as START , which contains
the location of the beginning of the list, and a next pointer sentinel denoted
by NULL ,which indicates the end of the list.
INFO LINK

c c 

c c 

c c Π
c
c c 
c
c c Œ
START c c 
c c 
c
  c c Œ
c
c c 
c c c 
c
c c 
c c 
c
c c 
c c c 
c
c c 
c c 
c
c c 
c
c c 
c c c ÿ
c c c 
 c c 
c
c c 
c
c c ÿ
c  c c 
c 
c c 
EXAMPLE:-
In this picture a linked list in memory where each node of the list contains a
single character.We can obtain a actual list of charactera, or ,in other
words, the string ,as follows:

START=13,so INFO[13]=L is the first character.

LINK[13]=3, so INFO[3]=I is the second character.

LINK[3]=21, so INFO[21]=S is the third character.

LINK[21]=10, so INFO[10]=T is the fourth character.

LINK[10]=9, so INFO[9]= Is the fivth character.

LINK[9]=19, so INFO[19]=C is the sixth character.

LINK[19]=7, so INFO[7]=O is the seventh character.

LINK[7]=15, so INFO[15]=M is the eighth character.

LINK[15]=8, so INFO[8]=P is the ninth character.

LINK[8]=23, so INFO[23]=L is the tenth character.

LINK[23]=17, so INFO[17]=E is the eleventh character.

LINK[17]=5, so INFO[5]=T is the twelveth character.

LINK[5]=12, so INFO[12]=E is the thirteen character.

LINK[12]=0, the null value so the list has ended.

In the other words,  c is the character string.

TRAVERSING A LINKED LIST:-


Let List be a linked list in memory.This algorithm traverses LIST,
applying an operation PROCESS to each element of LIST.The
variable PTR points to the node currently being processed.
[  
  
    
 
 !"# $!  
   %     &
 

# ' 

( #& 

SEARCHING A LINKED LIST:-


LIST is a linked list in memory.This algorithm finds the location
LOC of the node where ITEM first appears in LIST, or sets LOC =
NULL.
1. Set PTR := START.
2. Repeat steps while PTR=NULL:
3. If ITEM = INFO[PTR], then:

Set LOC := PTR, and Exit.


Else:
Set PTR := LINK[PTR]. [PTR now points to the next
node.]
[End of if structure.]
[End of step 2 loop.]

4. [Search is unsuccessful.] Set LOC := NULL.


5. Exit.

GARBAGE COLLECTION:-

 Free storage list or avail list.


 Garbage collection is invisible to programmer.
 Garbage collection takes place when:
€ CPU is idle
€ Running out of space
EXAMPLE:-
’  c c
c ccc cc c
cc
ccc c c 

ccc c
c
cccc
c cc !cc c c
 

ccc"!cc c#c 

ccc
$!cc c
c 

cc%c$!c c c


c ccc# c 
&c cc$!' cc
cccccccccccccccccccccccccccccccccccccccccccccccccccccccc

c    ÿ
c
Π 
START 
 

c 
 
  Œ
c
 
 
c

c   

c
ÿ 
  
AVAIL
   
c

 
  
c

  Œ
c

   
c

Π  
c
MALLOC FUNCTION IN C:-


c(cc c

 c

 c

)*c  c 

c

c  cc cc


+c, c-cccc cc-cc, c

cc  c
c