1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
schepotkina [342]
3 years ago
15

Develop Java methods to perform the following operations on an unordered list (using linked lists). What is the complexity of ea

ch of these algorithms. 1. Insert an element at the start (front) of the list 2. Insert an element at the end (rear) of the list 3. Insert an element at the middle of the list following an element already in the list. 4. Remove an element from the middle of the list
Computers and Technology
1 answer:
maxonik [38]3 years ago
4 0

Answer:

Check the explanation

Explanation:

Java Program to Implement Singly Linked List

import java. util. Scanner;

/* Class Node */

class Node

{

   protected int data;

   protected Node link;

   /* Constructor */

   public Node()

   {

       link = null;

       data = 0;

   }  

   /* Constructor */

   public Node(int d,Node n)

   {

       data = d;

       link = n;

   }  

   /* Function to set link to next Node */

   public void setLink(Node n)

   {

       link = n;

   }  

   /* Function to set data to current Node */

   public void setData(int d)

   {

       data = d;

   }  

   /* Function to get link to next node */

   public Node getLink()

   {

       return link;

   }  

   /* Function to get data from current Node */

   public int getData()

   {

       return data;

   }

}

/* Class linkedList */

class linkedList

{

   protected Node start;

   protected Node end ;

   public int size ;

   /* Constructor */

   public linkedList()

   {

       start = null;

       end = null;

       size = 0;

   }

   /* Function to check if list is empty */

   public boolean isEmpty()

   {

       return start == null;

   }

   /* Function to get size of list */

   public int getSize()

   {

       return size;

   }  

   /* Function to insert an element at begining */

   public void insertAtStart(int val)

   {

       Node nptr = new Node(val, null);  

       size++ ;  

       if(start == null)

       {

           start = nptr;

           end = start;

       }

       else

       {

           nptr. setLink(start);

           start = nptr;

       }

   }

   /* Function to insert an element at end */

   public void insertAtEnd(int val)

   {

       Node nptr = new Node(val,null);  

       size++ ;  

       if(start == null)

       {

           start = nptr;

           end = start;

       }

       else

       {

           end. setLink(nptr);

           end = nptr;

       }

   }

   /* Function to insert an element at position */

   public void insertAtPos(int val , int pos)

   {

       Node nptr = new Node(val, null);              

       Node ptr = start;

       pos = pos - 1 ;

       for (int i = 1; i < size; i++)

       {

           if (i == pos)

           {

               Node tmp = ptr. getLink() ;

               ptr. setLink(nptr);

               nptr. setLink(tmp);

               break;

           }

           ptr = ptr. getLink();

       }

       size++ ;

   }

   /* Function to delete an element at position */

   public void deleteAtPos(int pos)

   {      

       if (pos == 1)

       {

           start = start. getLink();

           size--;

           return ;

       }

       if (pos == size)

       {

           Node s = start;

           Node t = start;

           while (s != end)

           {

               t = s;

               s = s. getLink();

           }

           end = t;

           end. setLink(null);

           size --;

           return;

       }

       Node ptr = start;

       pos = pos - 1 ;

       for (int i = 1; i < size - 1; i++)

       {

           if (i == pos)

           {

               Node tmp = ptr. getLink();

               tmp = tmp. getLink();

               ptr. setLink(tmp);

               break;

           }

           ptr = ptr. getLink();

       }

       size-- ;

   }  

   /* Function to display elements */

   public void display()

   {

       System.out. print("\nSingly Linked List = ");

       if (size == 0)

       {

           System. out. print("empty\n");

           return;

       }  

       if (start. getLink() == null)

       {

           System. out. println(start. getData() );

           return;

       }

       Node ptr = start;

       System. out. print(start. getData()+ "->");

       ptr = start. getLink();

       while (ptr. getLink() != null)

       {

           System. out. print(ptr. getData()+ "->");

           ptr = ptr. getLink();

       }

       System. out. print(ptr. getData()+ "\n");

   }

}

/* Class SinglyLinkedList */

public class SinglyLinkedList

{  

   public static void main(String[] args)

   {            

       Scanner scan = new Scanner(System.in);

       /* Creating object of class linkedList */

       linkedList list = new linkedList();

       System. out. println("Singly Linked List Test\n");        

       char ch;

       /* Perform list operations */

       do

       {

           System. out. println("\nSingly Linked List Operations\n");

           System. out. println("1. insert at the start");

           System. out. println("2. insert at the rear");

           System. out. println("3. insert at the middle of the list");

           System. out. println("4. Remove from the middle of list");

   

           int choice = scan. nextInt();          

           switch (choice)

           {

           case 1 :

               System. out. println("Enter integer element to insert");

               list. insertAtStart( scan. nextInt() );                    

               break;                        

           case 2 :

               System. out. println("Enter integer element to insert");

               list. insertAtEnd( scan. nextInt() );                    

               break;                        

           case 3 :

               System. out. println("Enter integer element to insert");

               int num = scan. nextInt() ;

               System. out. println("Enter position");

               int pos = scan. nextInt() ;

               if (pos <= 1 || pos > list. getSize() )

                   System. out. println("Invalid position\n");

               else

                   list. insertAtPos(num, pos);

               break;                                        

           case 4 :

               System. out. println("Enter position");

               int p = scan. nextInt() ;

               if (p < 1 || p > list. getSize() )

                   System. out. println("Invalid position\n");

               else

                   list. deleteAtPos(p);

               break;

            default :

               System. out. println("Wrong Entry \n ");

               break;

           }

           /* Display List */

           list. display();

           System. out. println("\nDo you want to continue (Type y or n) \n");

           ch = scan. next(). charAt(0);                      

       } while (ch == 'Y'|| ch == 'y');              

   }

}

You might be interested in
Create a short document titled "Guide to web searches" that Sergio can give to users of the facility he supervises. The document
Studentka2010 [4]

Answer:

Jobs Seeker's

Web Search Guide

Sergio Escobar

PERFORMING A SEARCH:

All search engines will have a search field in which you are able to enter your search terms,

criteria, keywords, or even a website.

Search terms are the keywords a search engine will use to try to find the most relevant search

results.

If you’re looking for general information, just enter the name of the topic you’re

interested in into the search field.

So, if you’re looking for work, you can use the search terms ‘employment’ and ‘jobs’.

The search engine will return you a list of web pages that include the words

‘employment’ and ‘jobs’.

IF you’re looking for more specific information, you can narrow your search results by

using more specific search terms.

So, if you wanted employment opportunities in Phoenix, AZ, you could use the search terms:

‘local’, ‘employment’, ‘jobs’ and ‘Phoenix’.

Once you’ve entered your search terms and selected the search or go button, the search

engine will provide you with a list oF search results.

Depending on your search, you could get thousands or even millions of search results. This is

because search engines will usually list every single web page on the Internet that used those

search terms somewhere on a web page.

(However, the most current and/ or relevant results should be at the top of the list.)

Searching Strategy:

Using Boolean Operators:

use AND,OR,NOT between the words

ex: LOCAL AND JOBS

JOBS NOT IN NEWYORK

Proximity Operators:

With some search engines you can use proximity operators such as OpenText's NEAR operators or Webcrawler's ADJecent or the FOLLOWED BY operator.

With each of these operators, word order is important.

For example: if you place square brackets such as [local jobs] causes a hit if they are found within 100 words of each other.

Truncation (*)

You can use truncation on most search engines.

That is, you can use the asterisk (*) operator to end a root word.

For example: searching for comput* will find computer, computing, and computer jobs.

Note: the asterisk can not be the first or second letter of a root word.

Wildcard (?)

You can find words that share some but not all characters using the question mark (?) operator.

For example: Com?er J?b will find Computer Jobs and Computer Job.

Note: the ? can not be the first character in the search.

You may also use combinations of truncation (*) and single character wildcard (?) in your searches.

Conclusion:

These are just a few of the strategies and new tools trainers can use to make working on the web more productive.

As trainers continue to use the web they will soon see the next generation of web "knowledge tools" begin to emerge.

These will include multidimensional tools that are created to manage data on the web using factors such as "virtual neighborhoods of information,

" "organic structuring," and "mental model based searching and flying mechanisms" .

These are tools which are intended to make the world wide web more manageable for the user.

Let us now go back to my original statement...that the goals of search strategies and engines should be to increase your efficiency

and effectiveness when looking for information on the web.

Only you can decide which search/knowledge management strategies and tools actually improve your productivity.

It is my hope that this article helps you with making these decisions.

8 0
4 years ago
which dual-stack architecture allows ipv4 and ipv6 at the network layer to access a single tcp/udp stack
Archy [21]

The dual-layer-IP allows ipv4 and ipv6 at the network layer to access a single tcp/udp stack.

<h3>What is the dual IP layer?</h3>

The word dual-stack is a word that connote a full or total duplication of all stages in the protocol stack ranging from its applications to the network layer.

Note that the dual-layer-IP method often gives room for a computer to run IPv4 and IPv6 simultaneously  at the network layer, and all of the IP stack can access a different TCP/UDP stack.

Learn more about  architecture  from

brainly.com/question/9760486

6 0
2 years ago
By default, after how much time has elapsed in a client's DHCP lease will the client attempt to renew the lease?
maw [93]
The client will attempt to renew halfway through the time of the lease.
3 0
3 years ago
7d2b:00a9:a0c4:0000:a772:00fd:a523:0358
motikmotik

Answer:

yh3iuskjldnsjfhbcgfihekwfhei3wh8hfefbgp

Explanation:

6 0
3 years ago
PHOTOGRAPHY PLEASE HELP!
BARSIC [14]
1. Portfolios, folders, or drives
2. To make small touch ups and enhance your photos
3. People can steal your photos
4. Because they are trying to capture a story in a photo, and others can change the original intent of their work.
8 0
4 years ago
Other questions:
  • Using Matlab programming I need to rotate the line defined by x,y by 45 degrees around 2,2
    13·1 answer
  • 18. Applying what formatting option to your Excel workbook will make it easier to read when printed out?
    9·1 answer
  • Consider an environment in which there is a one-to-one mapping between user-level threads and kernel-level threads that allows o
    7·1 answer
  • If there are 8 opcodes and 10 registers, a. What is the minimum number of bits required to represent the OPCODE? b. What is the
    10·1 answer
  • What is 8 hours, 5 minutes, 22 seconds minus (-) 7 hours, 24 minutes, 37 seconds?
    6·1 answer
  • A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Ab
    11·1 answer
  • In what form do the hexadecimal numbers need to be converted for a computer’s digital circuit to process them?
    10·1 answer
  • _____ interviews rely on scenarios and reflections to evaluate an applicant’s skill set.
    9·2 answers
  • What is the volume of a rectangular prism with a length of 812 centimeters, width of 913 centimeters, and a height of 1225 centi
    12·1 answer
  • A mom is planning a theme park trip for her husband, herself, and their three children. The family has a budget of $500. Adult t
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!