Linked List ISC
Linked List ISC
class Node
int info;
Node link;
Write an algorithm OR a Method for deleting a node from a lined list. The
method declaration is given below:
Steps
1. Start
2. Accept info for the node to be deleted
3. if first nod is the desired one then
set temporary pointer to first node
Stop
else
Stop
else
6. move temporary pointer to the next node
7. Repeat step 5 & 6 until the temporay pointer reaches null
8. End
Method to delete a node in a linked list
int n= integer.parseInt(obj.radLine());
if(start.info==n)
a.start;
start= start.link;
a.link=null;
else
a=a.link;
while( a!=null)
if(a.info==n)
b.link=a.link;
a.link=null;
break;
b=a;
a.a.link;
class node
int p;
String n;
node next;
Steps
1. start
2. Set temporary pointer to the first node
3. Repeat steps 4 and 5 until the pointer reaches null
4. if the names matches with the parameter value then Print details, stop
5. else
6. Move temporary pointer to the next node
7. End
Method to search for a node in a linked list
void search( node start, String b)
int f =-1;
if(a.n equals(b))
f=1;
else
a=.a.next;
if (f==1)
System.out.println(a.p);
else
Steps
1. Start
2. Set a temporary pointer to the first node and counter to 0
3. Repeat steps 4 and 5 until the pointer reaches null
4. Increment the counter
5. Move the temporary pointer to the next node
6. Return the counter value
7. End
Method to count for the number of nodes in linked list
int c=0;
while (a!=null)
c++;
a= a.next;
return c;
class Node
int number;
Node nextNode;
Steps.
1. Start
2. Set temporary pointer to start node
3. Repeat steps 4 until it reaches null
4. move the pointer to the next node
5. create a new node, assign num to number and link to the temporary
node
6. End
Method to add a node at the end of an existing linked list
while(A!= null)
A= A.nextNode;
C.number = num;
C.nextNode = null;
A.next =C;
Method to print the sum of the nodes of odd integers in an existing linked
list.
void NodeCount( Nodes starPtr)
{
Nodes temp = new Nodes(starPtr)
int c=0;
while (temp!=null)
{
if( temp.num%2 !=0)
c=c+temp.num;
temp=temp.next;
}
System.out.println(c);
}
6. A linked list is formed from the objects of the class Node. The class
structure of the Node is given below:
class Node
{
String name;
Node next;
}
Write an Algorithm OR a Method to search for a given name in the
linked list. The method of declaration is given below:
boolean searchName(Node start, String v)
ALGORITHM:
Step 1. Start
Step 2. Set temporary pointer to the first node
Step 3. Repeat steps 4 and 5 until the pointer reaches null
Step 4. Search for the node. If found display details, exit
Step 5. Move pointer to the next node
Step 6. End
METHOD:
boolean searchName(Node start, String v)
{
Node temp=new Node(start);
while(temp.name.equals(v) = = false && temp.next!=null)
temp=temp.next;
if(temp.next!=null)
return true;
else
return false;
}
7. A linked list is formed from the objects of the class Node. The class
structure of the Node is given below:
class Node
{
int num;
Node next;
}
Write an Algorithm OR a Method to count the nodes that contain
only odd integers from an existing linked list and returns the count.
The method declaration is as follows:
int CountOdd( Node startPtr )
ALGORITHM:
Step 1. Start
Step 2. Set temporary pointer to the first node
Step 3. Repeat steps 4 and 5 until the pointer reaches null. Return count
Step 4. Check for odd and increment the counter.
Step 5. Move pointer to the next node
Step 6. End
METHOD:
int CountOdd(Node startPtr)
{
int c=0;
Node temp=new Node(startPtr);
while(temp != null)
{
if (temp.num % 2 != 0)
c++;
temp=temp.next;
}
return c;
}
8. A linked list is formed from the objects of the class Node. The class
structure of the Node is given below:
class Node
{
int n;
Node link;
}
Write an Algorithm OR a Method to search for a number from an
existing linked list.
The method declaration is as follows:
void FindNode( Node str, int b )
ALGORITHM:
Step 1. Start
Step 2. Set temporary pointer to the first node
Step 3. Repeat steps 4 and 5 until the pointer reaches null. Display
number not found
Step 4. check for number , if found display, exit
Step 5. Move pointer to the next node
Step 6. End algorithm
METHOD:
void FindNode(Node str, int b)
{
Node temp=str;
while(temp!=null)
{
if (temp.n == b)
{
System.out.prinln(b+” is found “);
break;
}
temp=temp.link;
}
}
9. A linked list is formed from the objects of the class Node. The class
structure of the Node is given below:
class Node
{
int num;
Node next;
}
Write an Algorithm OR a Method to find and display the sum of
even integers from an existing linked list.
The method declaration is as follows:
void SumEvenNode( Node str )
ALGORITHM:
Step 1. Start
Step 2. Set temporary pointer to the first node
Step 3. Repeat steps 4 and 5 until the pointer reaches null. Display
sum, exit
Step 4. check for even number, if found accumulate
Step 5. Move pointer to the next node
Step 6. End algorithm
METHOD:
void SumEvenNode(Node str)
{
Node temp=new Node(str);
int s=0;
while(temp!=null )
{
if (temp.num%2==0)
s=s+temp.num;
temp=temp.next;
}
System.out.println(“sum of even integers=”+s);
}
10.