Create a mirrored linked list in Java

Create a mirrored linked list in Java

By : user3865491
Date : January 10 2021, 01:57 PM
fixed the issue. Will look into that further Linked-List: Mirror
code :

Share : facebook icon twitter icon
How do I create a Linked List Data Structure in Java?

How do I create a Linked List Data Structure in Java?

By : ziqew
Date : March 29 2020, 07:55 AM
will be helpful for those in need The obvious solution to developers familiar to Java is to use the LinkedList class already provided in java.util. Say, however, you wanted to make your own implementation for some reason. Here is a quick example of a linked list that inserts a new link at the beginning of the list, deletes from the beginning of the list and loops through the list to print the links contained in it. Enhancements to this implementation include making it a double-linked list, adding methods to insert and delete from the middle or end, and by adding get and sort methods as well.
Note: In the example, the Link object doesn't actually contain another Link object - nextLink is actually only a reference to another link.
code :
class Link {
    public int data1;
    public double data2;
    public Link nextLink;

    //Link constructor
    public Link(int d1, double d2) {
        data1 = d1;
        data2 = d2;

    //Print Link data
    public void printLink() {
        System.out.print("{" + data1 + ", " + data2 + "} ");

class LinkList {
    private Link first;

    //LinkList constructor
    public LinkList() {
        first = null;

    //Returns true if list is empty
    public boolean isEmpty() {
        return first == null;

    //Inserts a new Link at the first of the list
    public void insert(int d1, double d2) {
        Link link = new Link(d1, d2);
        link.nextLink = first;
        first = link;

    //Deletes the link at the first of the list
    public Link delete() {
        Link temp = first;
        if(first == null){
         return null;
         //throw new NoSuchElementException(); // this is the better way. 
        first = first.nextLink;
        return temp;

    //Prints list data
    public void printList() {
        Link currentLink = first;
        System.out.print("List: ");
        while(currentLink != null) {
            currentLink = currentLink.nextLink;

class LinkListTest {
    public static void main(String[] args) {
        LinkList list = new LinkList();

        list.insert(1, 1.01);
        list.insert(2, 2.02);
        list.insert(3, 3.03);
        list.insert(4, 4.04);
        list.insert(5, 5.05);


        while(!list.isEmpty()) {
            Link deletedLink = list.delete();
            System.out.print("deleted: ");
Create list of numbers mirrored around zero (python)

Create list of numbers mirrored around zero (python)

By : Eric Emmanuel Roque
Date : March 29 2020, 07:55 AM
wish of those help If you want it to be strictly mirrored around 0, (i.e. always include 0 and the endpoints, and be perfectly symmetric about 0) you'll need a couple of steps.
First off, be aware of @NPE's comment above. Floating point math is not the same as decimal math!! This may seem beside the point, but it will bite you in certain circumstances.
code :
import numpy as np

def mirrored(maxval, inc=1):
    x = np.arange(inc, maxval, inc)
    if x[-1] != maxval:
        x = np.r_[x, maxval]
    return np.r_[-x[::-1], 0, x]

print mirrored(1, 0.3)
[-1.  -0.9 -0.6 -0.3  0.   0.3  0.6  0.9  1. ]
import numpy as np

def mirrored2(maxval, inc=1):
    return np.linspace(-maxval, maxval, 2*maxval // inc)

print mirrored2(1, 0.3)
[-1.  -0.6 -0.2  0.2  0.6  1. ]
Create an Linked List array of linked lists with a loop java

Create an Linked List array of linked lists with a loop java

By : user2380777
Date : March 29 2020, 07:55 AM
Does that help I have successfully implemented Radix sort but I have the following code that I would like to convert to be created by a loop. , Here you go:
code :
private static LinkedList[] bucket = new LinkedList[19];

static {
    for (int i = 0; i < bucket.length; ++i) {
        bucket[i] = new LinkedList();
How to create a linked list in java?

How to create a linked list in java?

By : donPardon
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , That's how the pointers in the list look internally, to actually add it to the list you need to do this:
code :
List<String> s = new LinkedList<>(); 

How to quickly create linked list in C/C++ just like java?

How to quickly create linked list in C/C++ just like java?

By : user61731
Date : March 29 2020, 07:55 AM
To fix this issue Java has a linked list object which can be used to quickly create a linked list using predefined functions. Does C or C++ have similar libraries too? I have an upcoming test and I want make the basic list quickly so that I can delve into the real problem. But making these linked lists take so much time! Do I have to switch to java or is there a way? , C++ stl contains both singly linkedlist and doubly linkedlist.
code :
using namespace std;

int main(){
    forward_list<int> singlyList1; //declaring singly linked list 

    singlyList1.assign({50,40}); // assign values to list
    singlyList1.push_front(60); // insert element at first position

    cout << "The elements forward list are : ";
    for (int&ele : singlyList1)
        cout << ele << " ";
    cout << endl;

    return 0;
#include <iostream>
#include <list>
#include <iterator>
using namespace std;

int main(){

  list<int> dblyList{1,2,3};


  cout << "\n Front : " << dblyList.front();
  cout << "\n Back : " << dblyList.back();

   return 0;

Related Posts Related Posts :
  • how to use izpack to make my jar application to installer?
  • What is meant by src in Java Eclipse?
  • Examples of good JPA Java Desktop Application
  • Translate Java to Python -- signing strings with PEM certificate files
  • Algorithm Analysis tool for java
  • Java serial comm API - what does inputstream.read() return if a timeout occurs?
  • How do I make a background thread in Java that allows the main application to exit completely? This works in Linux, but
  • How to add an image dynamically at runtime in java
  • Java App on Mac asking for allow network connections everytime
  • Best actively maintained Java XMPP Library?
  • Multi-Threaded Application - Help with some pseudo code!
  • Scoping a StringBuilder inside a for loop
  • How to specify hash algorithm when updating LDAP via Java?
  • Class not found exception (org.apache.openjpa.enhance.PersistenceCapable) thrown in a client of WLS 10
  • In Java ,where in memory are class functions put?
  • How do I test expectedExceptionsMessageRegExp (exception message) using TestNG?
  • Help In understanding Multi Dimentional Arrays
  • No bean named '...' is defined and Spring @Resource annotation
  • Singleton design pattern vs Singleton beans in Spring container
  • flashvars object was not working in mozilla browser
  • Shell script to import mysql dump file
  • What are the best practices to separate data from users
  • May I use com.google.code prefix for my packages?
  • How to set classpath in manifest file , while creating JAR from eclipse?
  • dealing with voice in java
  • Error: java.security.AccessControlException: Access denied
  • How to verify the root trust of a ceritifcate
  • Searching for a standalone JSP compiler
  • Spring 2.5 managed servlets: howto?
  • iBatis get executed sql
  • GRAPH: find an algorithm to determine the shortest path from one point to another in a rectangular maze?
  • Efficient JSON encoding for data that may be binary, but is often text
  • How to Read Java File Structure using Java?
  • Java-Hibernate-Newbie: How do I acces the values from this list?
  • Smallest executable for Windows
  • Java: matching two different type of array
  • how to accept valid e-mail id in text box?
  • How can I know where a Null Pointer Exception originated?
  • Memory limited image processing in server
  • Java Multiple ResourceBundles
  • How to serialize Java primitives using Jersey REST
  • Casting objects to Integer,string ,
  • Using Java how can I plot the path of a sprite in a straight line?
  • IntelliJ shortcut for inserting a null check?
  • Eclipselink and update trigger on multiple access to the database
  • How to ICMPs and traceroutes in Java
  • "NOT_SUPPORTED_BY_GUI" Exception in JCo
  • Controlling the order of PicoContainer startup
  • Transposing and Untransposing a String in java
  • Spring MVC- several parts/views from a controller
  • Critical tools that every Java Developer should have in his toolbelt?
  • How to get the compression ratio for a GZipped file?
  • Does TestNG has runner like SpringJUnit4ClassRunner
  • Understanding Java Wait and Notify methods
  • Sorting a text file by date - Date looks like DD/MM/YYYY
  • Subtracting days in a Calendar object
  • How to store and retrieve object of a swing component in database, java
  • Java invalid stream header Problem
  • How to send parameters with same encoding from javascript?
  • Authentication and authorization frameworks for java GUI applications
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk