• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
S_S

Merge Two Linked List

8 posts in this topic

Sorry i am opening this topic but i have problem with this exercise. It is not homework but it is a sample question for midterm. I couldn't solve it. If you believe me (because i konw your behaviours for people who want homework assignments) , please help. Tomorrow i have a midterm :( /// Write a function to merge two linked lists of integers that are sorted into ascending order. The result should be a third linked list that is the sorted combination of the original lists. Do not destroy the original lists. ///
0

Share this post


Link to post
Share on other sites
Node* a = l1.begin();
Node* b = l2.begin();


while (...)
{
if(*a<*b)
{
c.add(*a);
a = a->next();
}
else
{
c.add(*b);
b = b->next();
}
}



And then take care of if either a or b reaches the end of its list.
0

Share this post


Link to post
Share on other sites
std::list merged = std::list(list1).merge(std::list(list2));

std::list<int> merged(list1);
std::list<int> merged2(list2);
merged.merge(merged2);


Enigma

EDIT: Oops, should have checked that what I posted would actually compile!

[Edited by - Enigma on December 13, 2004 5:00:04 PM]
0

Share this post


Link to post
Share on other sites
That IS in C++. I mean it's pseudocode but it's basically C++. The only thing that's left for you to fill in is the condition on the while loop and some checks.
0

Share this post


Link to post
Share on other sites

l1 is list 1
l2 is list 2

let append_and_sort l1 l2 =
let l = List.append l1 l2 in
List.sort (compare) l


Hints:

a) Specify programming language if you want specific answers (don't expect this for homework though).
b) Show your working, although you say this isn't homework, you've given no real evidence to the contrary. Without giving us what *you've* done working towards the problem the rules say we musn't help you.

EDIT: this was written before the three replies ;)
0

Share this post


Link to post
Share on other sites
More information is needed before a really good answer can be given. Are the two lists already sorted? If so, go with yaroslavd's answer. Otherwise, just add the lists together then go ahead and sort that list.

I have no experience in sorting linked lists, but I would probably just put all the addresses in an array of int *, (removing each node from the list), perform a merge sort on the _values_ at the addresses, then recreate the list. Probably the simplest method. If you are pressed for time, I am sure a simple insertion sort could be done. No need to over complicate things.

Good luck!
-visage
0

Share this post


Link to post
Share on other sites
An implementation of Merge Sort should not involve any array of pointers. Doing so would make it far more complicated and inferrior performance-wise. You merely divide the list into two and recurse on each half unless a list only has 1 item. Then after the recursive calls you merge the lists together.

Quote:
Original post by nmi
Check out this page.

Whilst the link nmi posted is okay, bear in mind that their documented extension to bitonic sort for arbitrary n that they use does not actually work in many cases, should you consider that algorithm. Their workaround for 'n not a power of two' is flawed and I can reproduce the same flaw in their applet also, producing an incorrect sort result. I tried contacting the author about this but got no response. The same workaround does actually work in breadth-first mergesort though.

yaroslavd has got the right idea, but you also need to be careful which way the lists are sorted - Increasing or decreasing order.

I assume that these are not doubly-linked lists that they are talking about?
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0