/*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*/
#include<iostream>
using namespace std;
struct Node

    int data;
    Node *next;
    Node *prev;
}*head,*tail;
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;
}

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);
   else
      list_insert (head, value);
}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.