473,386 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

merge linked list

mithuncm
hai all,
any one, can you say how to merge two different linked list. I have 2 linked list where datas, & of corresponding time that datas send. I have to sort out datas according to time, to a single linked list. Do you have any idea?
Nov 25 '08 #1
5 6829
JosAH
11,448 Expert 8TB
You have to be able to compare two elements (each in its own list) and move the first element of a list to another list.

kind regards,

Jos
Nov 25 '08 #2
weaknessforcats
9,208 Expert Mod 8TB
It does help on a merge if each list is already sorted. Unless you do that, the merge cuold get very complicated.
Nov 25 '08 #3
Ganon11
3,652 Expert 2GB
You could always be lazy and merge the lists first, then sort it (such a merging would be as simple as pointing the tail of one list to the head of the other list), but weaknessforcats is right: keeping each list sorted internally will make the merging much easier to do while keeping the lists sorted.
Nov 25 '08 #4
@Ganon11

i had already used 3 linked list 1st for gathering all scattered data read from 500 mB .cap file , 2nd sorted according to IP and port , acknowledgment is checked and sorted to 3 rd one.. ..
2 & 3 linked list are sorted and done to a single one as 4th linked list..
according to time of data received but the problem is iteration of the linked list .. the application become slower and slower.
if i can merge it to 2nd or 3 rd it will keep much more speed , i hve also tried thread. Do you have any idea or any doc or books to reffer?
else my problem is solved.
thank you all
Nov 26 '08 #5
vmpstr
63
You can just keep the first linked list sorted, and insert items into the correct positions according to ordering. I mean, it is still a fairly slow operation. You can try using a balanced binary tree to insert things, that should speed things up a bit. In the end, because of the size of your data, it will still be fairly slow.

A good reference for more advanced data structures like red-black trees is
Introduction to Algorithms by Cormen, Leiserson, Rivest, and Stein (clrs)

If you just want the code, then I know that there is
Algorithms in C by Robert Sedgewick... there's probably a C++ version, but I'm not sure.
Nov 26 '08 #6

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

Similar topics

2
by: Kakarot | last post by:
I'm gona be very honest here, I suck at programming, *especially* at C++. It's funny because I actually like the idea of programming ... normally what I like I'm atleast decent at. But C++ is a...
3
by: Traci | last post by:
I need to do a mail merge letter from my database. The letter will be addressed to small companies and in the body of the letter I need to list employees of the company. There will be from 1 to 15...
1
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
by: anunaygupta | last post by:
Hello all, I have a data structures problem. Assume there are 2 linked lists L1 and L2. They merge into some node. L1 1->2->3->4->5->6 / L2 8->7->9->/ L1 and L2 merge in node with value...
7
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#,...
2
nabh4u
by: nabh4u | last post by:
hi friends, i have a program where i have to sort a double linked list using merge sort. i am having problem with changing the pointers of the list, like the previous and the next pointers of a...
7
by: mooon33358 | last post by:
I have a little problem with implementing a recursive merge sort I have to use a function mergesort that takes 3 arguments - an array, its size, and an help array(i.e mergesort(int array, int...
1
by: vekka | last post by:
Hi! Could someone please help me to understand the use of merge algorithm(conceptually) with linked lists. What I want to do in the linked list function is: the function gets two inputs, i.e the...
0
by: enigma08 | last post by:
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: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.