create a link list of integer numbers it will split the list into two different lists of odd and even numbers and display the resultant - singly-linked-list

We need to create a singly linked list then seperate the odd and even values into a even and odd singly linked list. I may be able to explain it but I am facing difficulty in figuring out the exact code.

Related

What exactly is a Circular Doubly Linked List? C++

I have do to an assignment where we are to do a doubly linked list with no head or tail. I want to find examples of this very thing so I can understand it better. Now a Circular Doubly Linked List C++ is just that is it not? When I look up this in google I get examples with head and/or tail. I just want clarification so I do not make a mistake and be way behind. I have asked the professor but I do not think he checks his emails as often as I would like.
Simple:
A "linked list" is when each node contains a pointer to the next.
A "doubly linked list" is where each node contains both a forward pointer (to the next element), and a backward pointer (to the previous element).
Finally, a "circular doubly linked list" has a finite length - the final element points forward to the first, in a "circle".
Every link list be composed of nodes.
Every node will be composed of tuples which are composed of (elements, links).
Every element is the very thing that is contained.
Every link is a pointer to another node.
Next circular linked list are those that have the link connected in such a way where when one transverse the links one can arrive to the start without any change in direction.
This is can be done singularly or through multiple directions.

Implementation of non increasing list with STL C++

In a problem inputs are several lists of numbers,
Ex-
(1,5,4,3), (2,7,3,1,5), (1,9,1,7,3,7,2), (3,5,4,2,3).
where each list may appear twice.
In the final output distinct lists should be printed, in which elements in each list should be sorted in non increasing order, as well as lists should be sorted like that.
Is it possible to implement this whole thing with map in c++ ?
Output for the above example should be
9,7,7,3,2,1,1
7,5,3,2,1
5,4,3,3,2
5,4,3,1
Simply,set of unique lists where within each lists numbers again sorted in non increasing order.
std::set will definitely help you. You will get a unique sorted list as the resultant set if you insert your list into a std::set<int>
Edit:
std::set<std::multiset<int, std::greater<int>> myList;
Inner set going to sort in non increasing order and keeping duplicates elements, and outer set going to keep only unique list of inner list.

Running mergesort on two linkedLists that are coupled

I have the following problem and would like to see if somebody could tell me if I'm on the right track with my approach:
I want to do a "rolling window" kind of computation on two linked lists and for that I need them to be sorted by magnitude. If I just have one linked list, writing the corresponding mergesort is not the problem. However, now I'm wondering how I should go about the fact that I have two linked lists where I want to have the corresponding elements from list 1 and list 2 move together as I sort by the magnitude of list 1. If this is not entirely clear, this is what I mean:
In list 1, I want to do a sort by magnitude, so basically just rearrange the pointers. Whenever I move element "n" in one list, however, I also need to move the corresponding element "n" in the other list to the same position as the element from the other one.
Would my approach of using mergesort for this be the right way to go or does anyone know a better approach? I am having a hard time imagining how I would go about reordering the second list while mergesorting the first one since the second list is not necessarily going to be sorted by magnitude anymore and I need the individual elements to correspond to each other.
Thanks!
Marc
Just create a list of pairs of corresponding elements, and then sort the list by the first element of the pair.

Can a linked list have no data elements in it and still be a linked list?

I read this while studying for interview questions:
"A linked list must have two things. It must have some data in each node, and it must have a reference to the next node. "
But can a linked list just have references to the next node?
No, it will not be a linked list (by definition).
a linked list is a data structure consisting of a group of nodes which together represent a sequence. Under the simplest form, each node is composed of a data and a reference (in other words, a link) to the next node in the sequence; more complex variants add additional links. This structure allows for efficient insertion or removal of elements from any position in the sequence.
Linked list - wiki
I think that you just asked a bad question.
What would be the meaning of linked list , with nodes of empty information? You can implement it, but there is no meaning.

Using sorting algorithms on a Queue?

I'm using Queue Abstract Data Type which is based on Singly Linked List. I want to sort the data which Queue keeps in 3 ways: First with merge sort, second with quick sort, third with heap sort. So is there anyone can help about this?
Ordinarily a queue is sorted by insertion order - items are sorted by the order in which they were inserted into the queue. It appears you want to break that essential quality of a queue.
I'm only going to cover merge sorting with this answer. Hopefully others will cover the other algorithms or you can derive them yourself.
A single linked list can be treated as a list of lists simply by knowing when one list ends and another begins. For a merge sort you need to start with sorted lists - if each list has a length of 1, it is sorted simply because no other order is possible. Merging two linked lists into one is easy - you take the smallest item from each of two lists and link it into a new list, until both lists are exhausted. So for the first pass, you break the list into sublists of length 1, and combine them into sublists of length 2. The second pass you merge the sublists of length 2 into sublists of length 4. Each pass doubles the size of the sorted sublists. You're finished when the size of the sorted sublist is greater or equal to the size of your entire list.