Aptitude (12) C (2) C++ (10) CSS (1) Data Structure (2) English (7) General (14) HTML (3) Integration (1) Itinerary and Travel Cost (1) Java (29) JQ (5) JS (5) JSP (1) Lightning (14) logical (3) Math (1) Music Notation (17) MySql (4) Network (1) Regex (1) salesforce (131) Servlet (4) SF Admin (31) SF Dev (102) SQL (4) SQL_SERVER (1) StudyPoints (2) ytChannels (2) अन्ताक्षरी (4)

Create Single Linked List

Node Definition:

public class W
{
public class NodeDef
    {
     public Contact Value=new Contact();
     public NodeDef Ref;
    }

 public class SingleLinkedList
    {
     public NodeDef InitNode;
     public NodeDef NextNode;
 
    }
}




Create Single Linked List:
public class Util
{
public static W.SingleLinkedList getContactInSingleLinkedList()
{
  w.SingleLinkedList objSLL=new w.SingleLinkedList();
  List<Contact> lstContact=[Select Name from Contact];
  for(Contact objContact :lstContact)
  {
    if(objSLL.InitNode==null)
    {
    objSLL.InitNode=new W.NodeDef();
    objSLL.InitNode.Value=objContact;
    objSLL.InitNode.Ref=null;
    }
    else if(objSLL.NextNode==null)
    {
    objSLL.NextNode=new w.NodeDef();
    objSLL.NextNode.Value=objContact;
    objSLL.NextNode.Ref=Null;
    objSLL.InitNode.Ref=objSLL.NextNode;
    }
    else
    {
    w.NodeDef n=new w.NodeDef();
    n.Value=objContact;
    n.Ref=Null;
    objSLL.NextNode.Ref=n;
    objSLL.NextNode=n;
    }
  }
return objSLL;
}
}

No comments: