Now make a program so that it stores the values in increasing order, i.e., each time a value is added it is placed into its proper position in the list.
Here is my code, I cant get it to put them in increasing order.
#include <iostream>
using namespace std;
struct ListNode
{
int data;
ListNode *next;
ListNode(int d, ListNode *next1 = NULL)
{
data = d;
next = next1;
}
};
int main()
{
ListNode *numberList = NULL;
int size, number, check;
int yes = 0;
cout << "How many intergers are going to be entered ";//asks for how many numers
cin >> size;
for (int count = 0; count < size; count++)
{
cout << "Enter an integer " << count + 1 << ": ";//enter a numbrr
cin >> number;
numberList = new ListNode(number, numberList);
}
cout << "What integer do you want to check from the list ";//enter numebr from list
cin >> check;
cout << "The list contains\n";//tells the list
ListNode *ptr = numberList;
while (ptr != NULL)
{
if (ptr->data == check)
{
yes = 1;
}
cout << ptr->data;
cout << " ";
ptr = ptr->next;
}
if (yes == 1)
{
cout << "\n\n" << check << " is in the list.\n";//if the entered number is in list
}
else
{
cout << "\n\n" << check << " is not in the list.\n";//if entered number is not in list
}
return 0;
}