Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Link 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

https://sites

https sites.google
sites google.com
google com/site
com site/javaprogramsisc
site javaprogramsisc/
javaprogramsisc ISC Theory Questions 143

111 A linked list is formed from the objects of the class,


class ListNodes
{
int item;
ListNodes next;
}

Write a method OR an algorithm to compute and return the sum of all integers items stored in the
linked list. The method declaration is specified below:
int listsum(ListNodes start);
[2010]

STEP 1 : Set the pointer to starting node.


STEP 2 : Repeat step 3 and 4 until end or Null or empty
STEP 3 : Accumulate item of node in variable
STEP 4 : Move pointer to next node
STEP 5 : Display result
STEP 6 : STOP

int listsum(ListNodes start)


{
int t=0;
ListNodes r = start;
while(r != null)
{
t= t + r.item;
r=r.next;
}
return t;
}

112 A linked list is formed from the objects of the class,


class Node
{
int info;
Node link;
}

Write an algorithm OR a method for deleting a node from a linked list.


The method declaration is given below :
void deletenode( Node start)
[2011]
STEP 1 : Start.
STEP 2: Accept info for the node to be deleted
STEP 3 : if first node is the desired one then
Set temporary pointer to first node
Move the pointer of the first node to the next
Set temporary pointer to null
Stop
else
STEP 4 : Move temporary pointer to next node
https://sites
https sites.google
sites google.com
google com/site
com site/javaprogramsisc
site javaprogramsisc/
javaprogramsisc ISC Theory Questions 144

STEP 5 : If the desired node is found the


Set the pointer of the previous node to the next node to be deleted
Set temporary pointer to null
Stop
else
STEP 6 : move temporary pointer to the next node
STEP 7 : repeat step 5 and 6 until the temporary pointer reaches null
STEP 8 : End

void deletenode(Node start)


{
System.out.println(“enter info for the node to be deleted”);
int n=Integer.parseInt(obj.readLine());
Node a = new Node(start);
if(start.info==n)
{
a=start;
start=start.link;
a.link=null;
}
else
{
a=a.link;
Node b = new Node(start);
while(a!=null)
{
if(a.info==n)
{ b.link=a.link;
a.link=null;
break;
}
b=a;
a=a.link;
}
}
}
113 A linked list is formed from the objects of the class,
class node
{
int p;
String n;
node next;
}

Write an algorithm OR a method to search for a name and display the contents of that node. The
method declaration is given below :
void search( node start, String b)
[2012]
STEP 1 : Start
STEP 2 : Set the pointer to first node
STEP 3 : Repeat Step 4 and 5 untill pointer is not null
https://sites
https sites.google
sites google.com
google com/site
com site/javaprogramsisc
site javaprogramsisc/
javaprogramsisc ISC Theory Questions 145

STEP 4 : if name matches with input display name


STEP 5 : move the pointer to next node
STEP 6 : End

void search( node start, String b)


{ node a = new node(start)
int f= -1;
while(a != null && f == -1)
{
if(a.n.equals(b) ) f= 1;
else a = a.next;
}
if( f == 1) System.out.println(a.p);
else System.out.println(“Node not found”);
}

114 A linked list is formed from the objects of the class,


class Node
{
int item;
Node next;
}

Write an Algorithm OR a Method to count number of nodes in the linked list.


The method declaration is given below :
int count( Node ptr_start)
[2013]

STEP 1 : Start
STEP 2 : Set pointer to first Node
STEP 3 : Set count = 0
STEP 4 : Repeat Step 5 and 6 until pointer is not null
STEP 5 : count ++
STEP 6 : move pointer to next node
STEP 7 : Display count
STEP 8 : End

int count( Node ptr)


{
Node a = new Node(ptr);
int c=0;
while(a != null)
{
c++;
a = a.next;
}
return c;
}
https://sites
https sites.google
sites google.com
google com/site
com site/javaprogramsisc
site javaprogramsisc/
javaprogramsisc ISC Theory Questions 146
115 Write the algorithm for push operation (to add elements) in an array based stack.
[2013]
STEP 1 : If top>= capacity then Overflow, Exit
STEP 2 : top = top +1
STEP 3 : Stack[top] = value

116 A linked list is formed from the objects of the class:


class Node
{
int number;
Node nextNode;
}

Write an Algorithm OR a Method to add a node at the end of an existing linked list.
The method declaration is as follows:
void addnode(Node start, int num)
[2014]
STEP 1 : Start
STEP 2 : Set temporary pointer to start node
STEP 3 : Repeat step 4 until it reaches null
STEP 4 : Move pointer to the next node
STEP 5 : Create new node
STEP 6 : Assign num to number
STEP 7 : Stop

void addnode( Node start, int num)


{
Node A = new Node(start);
while(A != null)
A = A.nextNode;
Node C = new Node( );
C.number = num;
C.nextNode = null;
A.next = C;
}

117 Link Lists are linear data structure. Create Algorithms for the following operations:
(i) Insertion of a Node at the beginning in a Link List.
(ii) Deletion of the first Node in a Link list.
[2010 SP]
118 A Linked List is formed from the objects of the class,
class Node
{
int num;
Node next;
}
Write the algorithm OR a method for inserting a node in the end of the list.
The method declaration is given below :
void insertnode(Node start)
[2013SP]

You might also like