Single Linked List Using Java Web Service: 1. Source Code

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

|SOA Lab

December 22, 2015|4:22:14 PM

1. SINGLE LINKED LIST USING JAVA WEB SERVICE


1. SOURCE CODE
package sll;
import java.util.ArrayList;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
// node declaration
class node
{
int d;
node link;
}
// create a dynamic LL
@WebService(serviceName = "SingleLinkedList")
public class SingleLinkedList {
ArrayList lt=new ArrayList();
node root=null;
@WebMethod(operationName = "CreateList")
public String CreateList(@WebParam(name = "parameter") String values) {
String[] num=values.split("[ ,]");
1

|SOA Lab

December 22, 2015|4:22:14 PM

// clear the list


lt.clear();
for(int i=0;i<num.length;i++)
{
lt.add(num[i]);
}
node ii=null;
int c=0;
if(lt.isEmpty()==false)
{
for(int i=0;i<lt.size();i++)
{
// if it is 1st node
if(i==0)
{
// allot the memory for root node
root=new node();
root.d=Integer.parseInt(lt.get(i).toString());
// set the base address to ii node
ii=root;
c++;
}
2

|SOA Lab

December 22, 2015|4:22:14 PM

else
{
ii.link=new node();
ii=ii.link;
ii.d=Integer.parseInt(lt.get(i).toString());
c++;
}
// if it is last node
if(i==lt.size()-1)
{
ii.link=null;
}
}
return "Single Linked List is created successfully with "+String.valueOf(c)+" nodes..." ;
}
else
return "List is empty!plz submit the elements "+String.valueOf(c);
}
// display the elements
@WebMethod(operationName = "Dispaly")
public String Dispaly() {
// set the base address to node dd
3

|SOA Lab

December 22, 2015|4:22:14 PM

node dd=root;
StringBuffer sb=new StringBuffer();
if(dd!=null)
{
while(dd!=null)
{
sb.append(dd.d+"-->");
dd=dd.link;
}
return "Elements in the LL:\n"+sb.toString();
}
else
return "List is empty!Plz add elements";
}
}

|SOA Lab

December 22, 2015|4:22:14 PM

2. OUTPUT
2.1 CREATE A DYNAMIC LIST

|SOA Lab

December 22, 2015|4:22:14 PM

2.2 SUCCESS STATUS

|SOA Lab

December 22, 2015|4:22:14 PM

2.3 SLL MENU

|SOA Lab

December 22, 2015|4:22:14 PM

2.4 DISPLAYING ELEMENTS IN LINKED LIST

You might also like