how can I write a mergeSort in c++ using linked list?
406489
http://www.cs.uaf.edu/2006/spring/cs311/ points to source code at http://www.cs.uaf.edu/2006/spring/cs311/docs/merge_sort.cpp
1108238
I can provide you complete programs of data structures (linked list, array handling, stacks, queues, tress, graphs, and other algorithms). for this you have to provide me your information and details for what purpose you have to use this? and what your are doing currently. you can communicate me on my email address. abhi_patni@yahoo.com.
550757
I have heard this question so many times that I decided to look it up on the net and I found a very good site that explains it very well, step by step.\nSo I will simply link that one here. This is the C equivalent, you can modify it for c++!\n\nhttp://www.iwebthereforeiam.com/programming/selfWrite.asp\n\nEnjoy!
781094
Nobody is going to do your homework for you. \n\nIf you're supposed to write code examples that illustrate how two comparable programs might look, then do this. Write some simple programs in C, and then re-write the same program in C++ but put the functions your void main calls in a class and instantiate the class.
41764
you can find a very good tutorial at the link.\n\nNo need to write whats already writtenm =)
195503
There is no structure in Java.\n\nProbably you are confusing with C++>
971319
#include <iostream>\n#include <iomanip>\n\nusing namespace std;\n\nint main() {\n\n  cout << "Welcome to F&#92;'Zone&#92;n"\n      << "&#92;n"\n      << "Please select from the following menu.&#92;n"\n      << "&#92;n"\n      << "1: Quarter pounder combo&#92;n"\n      << "&#92;n"\n      << "2: Bacon burger&#92;n" \n      << "&#92;n"\n      << "3: Swiss mushroom burger&#92;n"\n      << "&#92;n"\n      << "To place your order, enter the number of the meal you would like.&#92;n"\n      << "For instance enter 2 for a Bacon Burger.&#92;n"\n      << "&#92;n"\n      << "Please enter your selection now: ";\n  char x;\n  x = getchar();\n  double total = 0.0;\n  switch (x) {\n    case '1' :\n      total = 4.59;\n      cout << "Would you like a &#92;'biggy&#92;' size? It costs $0.39 extra.&#92;n"\n          << "Type in a 'Y' or a 'N': ";\n      //x = getchar();\n      cin >> x;\n      if (x == 'Y') {\n        total += 0.39;\n        cout << "You have chosen to have a &#92;'biggy&#92;' size.&#92;n";\n      }\n      cout << "Would you like cheese with that? It costs $0.25 extra.&#92;n"\n          << "Type in a 'Y' or a 'N': ";\n      //x = getchar();\n      cin >> x;\n      if (x == 'Y') {\n        total += 0.25;\n        cout << "You have chosen to have cheese.&#92;n";\n      }\n      break;\n    case '2' :\n      // similar to 1, just change the price and messages.\n      break;\n    case '3' :\n      // similar to 1, just change the price and messages.\n      break;\n    default :\n      cout << "You have not ordered a menu item.";\n      return 1;\n  }\n  cout << "The total of your order is $" << setiosflags(ios::fixed)\n      << setprecision(2) << total << resetiosflags(ios::fixed);\n}
473239
Several problems:\n\n>  bubble_sort(names[3]);\n\nthis is accessing the 4th element of the names array (first 3 elements are at indices 0, 1, and 2). this is why you're getting your output, it's not sorting anything! i'm surprised this program didn't crash. instead you simply want to pass 'names' as the parameter - this means you are passing the entire array as a parameter, not a single element of the array. proper:\n   bubble_sort(names);\n\n>           if (array[j+1] > array[j])\n\nthis would sort the array opposite the way you want it. simple fix is using less-than instead of greater-than. BUT, if i'm not mistaken, you can't compare strings like that. you have to use strcmp, like this:\n            if (strcmp(array[j+1], array[j]) < 0)\notherwise, you are just comparing pointers.
747191
The only difference is that the Double Linked List contains both a pointer to the next node, similar to a Single Linked List, and it also contains a pointer to the previous node. This allows the client to traverse the list both forward and backwards with little effort.\n\nSay you needed to get to the previous node with a single linked list, you would have to start back at the beginning of the list and walk down to it. Or create another node object in your client application that remembers the previous node. With a Double Linked List it is as simple as hitting rewind. ;-)
654224
#ifndef QUEUE_H_\n#define QUEUE_H_\nFile: queue.h\ntypdef item_t int;\nstruct Queue  {\n   item_t contents;\n   Queue* next;\n};\n\n/* Public Interface */\n/* Adds a new item to the end of the queue */\nvoid enqueue(item_t datum, Queue* head);\n/* Removes the head of the queue. */\nQueue* dequeue( Queue* head );\n/* Returns the element at the top of the queue */\nitem_t* top(Queue* head); \n#endif\n--------\n\nFile: Queue.c\n\nvoid enqueue(item_t datum, Queue* current){\n      if (current == NULL){ \n           current = malloc(sizeof(Queue));\n           current->contents = dataum;\n           current->next = NULL;\n           return;\n       }\n      while (current->next != NULL){\n         current = current->next;\n      }\n      current->next = malloc(sizeof(Queue));\n      current->next->contents = datum;\n      current->next->next = NULL;\n      return;\n  }\nQueue* dequeue(Queue* head){\n   if (head == NULL){ return head;}\n   Queue* trash = head;\n   head = head->next;\n   free(trash);\n   trash = NULL;\n   return head;\n}\n\nitem_t* top(Queue* head){\n   if (head == NULL){ return NULL; }\n   else {\n      return &head->contents;\n  }\n}
698365
What you are trying to do is actually part of a larger sorting algorithm called "Merge Sort".\n\nhere is an example:\nhttp://mathbits.com/MathBits/CompSci/Arrays/Merge.htm\n\nYou would keep merging the sorted arrays in set K into the "master" sorted array.  Thus, you would only be working with two sorted arrays at any one time.\n\nSearch the net for "Merge Sort" for other implementations.
346423
check out http://www.planet-source-code.com - I don't do C++, but I use that site all the time, and it has great examples in source code form.
12275
Follow this link:\n\nhttp://www.thefreecountry.com/compilers/cpp.shtml\n\n:)
730115
read KNUTH! that's a classic question.\nhe is the king of algorithms! He wrote the book!\n\n\nbasically sort a pre-sorted list.
115853
#include <iostream>\n#include <vector>\nusing namespace std;\n#define rep(i, n) for((i) = 0; (i) < (n); (i)++)\n#define rep2(i, k, n) for((i) = k; (i) < (n); (i)++)\nvoid f21();\nint n;\ndouble mat[100][100];\nint main()\n{\nwhile(true)\n{\ncin >> n;\nif(!n) break;\nmemset(mat, 0, sizeof(mat));\nf21();\n}\nreturn 0;\n}\n\nvoid f21()\n{\ncout << "****************************************" << endl;\ncout << "*          INVERSE OF MATRIX           *" << endl;\ncout << "****************************************" << endl;\n\ncout << "ORDER OF THE MATRIX: " << n << endl;\ncout << "ENTER ELEMENT ROW-WISE" << endl;\nint m = 2*n;\nint i, j, k;\nrep(i, n) {\nrep(j, n) {\ncin >> mat[i][j];\ncout <<"&#92;t";\nprintf("%5.3lf", mat[i][j]);\n}\nrep2(j, n, m) {\nif(i == (j-n)){\nmat[i][j] = 1;\ncontinue;\n}\nmat[i][j] = 0;\n}\ncout << endl;\n}\n\ncout << endl << "INVERSE MATRIX: " << endl;\ndouble pivot, comm;\nrep(i, n) {\npivot = mat[i][i];\nif(mat[i][i] == 0){\ncout << "DIVISION BY ZERO." <<endl;\nreturn;\n}\nrep(j, m) mat[i][j] = mat[i][j]/pivot;\nrep(j, n) {\nif(i == j) continue;\ncomm = mat[j][i];\nrep2(k, i, m) {\nmat[j][k] = mat[j][k] - (comm*mat[i][k]);\n}\n}\n}\n\nrep(i, n) {\nrep2(j, n, m) {\ncout <<"&#92;t";\nprintf("%6.4lf", mat[i][j]);\n}\ncout << endl;\n}\ncout << endl;\n}\n\n/*This is writen in C++ this will output the inverse of a Matrix\ninput:\n4\n1 2 3 4\n2 1 4 2\n2 5 7 12\n1 -1 3 11\n\n5\n1.173 -0.634 0 0 0\n-0.539 1.173 -0.634 0 0\n0 -0.539 1.173 -0.634 0\n0 0 -0.539 1.173 -0.634\n0 0 0 -0.539 1.173\n\n0\n*/
598181
From what I remember, a dequeue just lets you queue/dequeue from either end.  So, just write a node class with whatever things you need to store in the nodes, and pointers to the next object and previous object.  In the dequeue class, put in methods to change the pointers based on what's happening.  If just creating a dequeue, then pointers in node should both be null.  If you have a chain already, then dequeuing from front should make the one behind it point to null.  If dequeueing from rear, then the one in front of it should point to NULL in the rear.  That sort of thing.
399780
I assume that since you're asking about linked lists, you can probably read code to some extent. =)\n\nAnyways, here's a link to a project on CodeProject that does exactly what you're asking for; along with source code so that you can see how it's done.