473,499 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Merge sort help

1 New Member
I need to merge sort two linked lists, each has a header and the elements are all ints.

I've tried adapting some generic code, but have run into a problem - errors that are similar to this one:

split(AlgSet.LLAlgSet) in AlgSet.LLAlgSet cannot be applied to (Node<java.lang.Integer>)

I see how that is happening as I'm giving it an element next instead of an actual list. Can someone help me out? I don't think it'll take much to fix it, and I am not that skilled in Java.

Expand|Select|Wrap|Line Numbers
  1. public LLAlgSet merge (LLAlgSet list1, LLAlgSet list2) {
  2.  
  3.     if (list1 == null) return list2;
  4.     if (list2 == null) return list1;
  5.     if (list1.element < list2.element) {             
  6.         list1.next = merge (list1.next, list2);
  7.         return list1;
  8.     } // end if
  9.     else {
  10.         list2.next = merge (list1, list2.next);
  11.         return list2;
  12.     } // end else*/
  13.  
  14. }
  15.  
  16.     public LLAlgSet merge_sort (LLAlgSet list1) { 
  17.     if (list1 == null || list1.next == null)
  18.            return list1; // checks for empty or single list
  19.     LLAlgSet list2 = split (list1);
  20.     list1 = merge_sort (list1);
  21.     list2 = merge_sort (list2);
  22.     return merge (list1, list2);
  23.         }
  24.  
  25.     public LLAlgSet split (LLAlgSet list1) {
  26.     if (list1 == null || list1.next == null) return null;
  27.     LLAlgSet list2 = list1.next;
  28.     list1.next = list2.next;
  29.     list2.next = split (list2.next);
  30.     return list2;
  31. }
Mar 4 '08 #1
0 1468

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4591
by: Kevin King | last post by:
I have a question about an assignment I have. I need to count the number of comparisons in my merge sort. I know that the function is roughly nlog(n), but I am definately coming up with too many...
5
2822
by: Tom Keane | last post by:
Okay, so the deal is, I am doing a mail merge document in order to print invoices. The field I get the amount of money is "invAmount". What I would like to do is be able to manipulate this number...
1
12822
by: Booser | last post by:
// Merge sort using circular linked list // By Jason Hall <booser108@yahoo.com> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> //#define debug
9
5592
by: rkk | last post by:
Hi, I have written a generic mergesort program which is as below: --------------------------------------------------------- mergesort.h ----------------------- void MergeSort(void...
7
14234
by: Zeba | last post by:
Hi, I have to write program in C# to merge sort a linked list (doubly linked). Is it true that the best way to do it is copy it into an array, sort it and then convert back ? I'm new to C#,...
16
3562
by: Sam Durai | last post by:
Hello, I need to merge a small table (of rows less than 100,sometimes even 0 rows) to a big table (of rows around 4 billion). I used the PK of the big table as merge key but merge does a table scan...
2
2874
by: mqueene7 | last post by:
below is my code for my merge sort but I can't get it to sort properly. I am trying generate random numbers based on input from the user and then sort those random numbers. Can you tell me what I...
5
4466
by: Sarahger9 | last post by:
I am trying to generate a random vector of integers and sort them using merge sort. I am having trouble with the code. It is long, but I would appreciate if someone could take a look at it and see...
9
8196
by: Tem | last post by:
List<inta = new List<int>(); a.Add(1); a.Add(2); a.Add(3); List<intb = new List<int>(); b.Add(3); b.Add(4); b.Add(5);
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.