/*can you help me with this
this is double linked list that helps you to 
sort integer value in increasing order
I hope I will get answer thank you*/
using namespace std;
struct Node

    int data;
    Node *next;
    Node *prev;
void main()
    head = NULL;
    int n;
    Node *p, *temp;
    cout << "Enter Number of Nodes ";
    cin >> n;
    cout << "Enter elements\n";
    for (int i = 1; i <= n; i++) {
        if (head == NULL) {
            head = new Node;
            tail = head;
            cin >> head->data;
            head->next = NULL;
            head->prev = NULL;
        else {
            p = head;
            tail = new Node;
            while (p != NULL)
                p = p->next;
            temp = new Node;
            cin >> temp->data;
            p->next = temp;
            temp->prev = p;
            temp->next = NULL;
            tail = temp;
    Node *q = head;
    while (q != NULL)
        cout << q->data << " ";
    cout << endl;
3 Years
Discussion Span
Last Post by L7Sqr

What problems are you having? We wont just do the problem for you but we'd be happy to help you along with any issues you have.

I'd suggest you make a separate function that handles inserting into a list. That way, in that function, you can manage how items are placed into the list - including when you want them sorted. That change would look something like:

std::cin >> n;
std::cout << "Enter elements" << std::endl;
for (int i = 0; i < n; ++i) {
   std::cin >> value;
   if (NULL == head)
      head = make_list (value);
      list_insert (head, value);

Of course, you need to provide the definition of make_list and list_insert.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.