I would like to understand in more detail the difference in the performance of different tasks of a coherent list in two diametrically opposite languages: c and java .

More specifically: compare and find differences in adding and removing an item to the linked list / from the linked list.

And the matter is not in the code (I have it), but in the technique of application.

Thanks in advance for the answer!

Take the example code on with:

 void deleteCar(char* reg) { struct LinearNode *current, *previous; bool found = false; if (isEmpty()) printf("Error - there are no nodes in the list\n"); else { printf("**************Sell car:**************\n"); current = previous = front; while (!found && current != NULL) { //check by comparing if registration number exists and car is reserved if ((strcmp(reg, current->element->registration) == 0) && (current->element->reserved == true)) { found = true; } else { //go to the next node previous = current; current = current->next; }//end else } //end while if (!found) printf("Error - there is not such car with registration number %s or this car is not reserved\n", reg); else { //if found if (current == front) { front = front->next; free(current); //remove node from list } //end else else { previous->next = current->next; free(current);//remove node from list } //end else printf("Car with registration number %s has been deleted\n", reg); }//end else }//end else }// end deleteNode 

and here is the method for deleting an item on java:

 public boolean delete(T element){ LinearNode<T> previous = list; LinearNode<T> current = list; boolean found = false; while (!found && current != null) { if (current.getElement ().equals (element)) { found = true; } else { previous = current; current = current.getNext(); } } //found loop if (found)//we fount the element { if(current == this.list){ this.list.getElement(); this.list = this.list.getNext(); } else if(current == this.last){ previous.setNext (null); this.last = previous; } else{ previous.setNext(current.getNext()); current.setNext (null); } this.count--; } return found; } 

Is it possible after these examples to say that in java you can use code that will be generic , unlike c ?

  • What criteria are you going to compare? - αλεχολυτ
  • for example, с uses pointers , and java uses references . but apparently this is the same thing) so I'm trying to find the main differences. and I also try to find the main criteria in order to figure out what to look for - Alex
  • @Alex and the pointer and the link point to the next list item, yes. If you show code samples, you can still look for differences. That's the way you can write in C and in Java, and the differences will be different - Schullz
  • Thank you, updated the post, asked another question - Alex
  • @Alex and by the way, is the code debugged and tested? Works? - Schullz

1 answer 1

In terms of implementing the self-written linked list, Java and C are practically the same, the principle is the same. A class or structure of a list item is created, it contains some information and a link to the next item. In C, a pointer with an asterisk, in Java without it. You can simply list all the differences in language syntax.