M
massimo
Hey,
I wrote this program which should take the numbers entered and sort them
out. It doesn¹t matter what order, if decreasing or increasing.
I guess I'm confused in the sorting part. Anyone has any advices??
#include <iostream>
using namespace std;
struct link
{
int data;
link *pNext;
link *pHead;
link *current;
};
class linkList
{
private:
link *pHead;
public:
linkList()
{ pHead = NULL;}
void add_Item(int d);
void display();
};
void linkList::add_Item(int d)
{
link *pPrev;
link *pSucc;
pPrev = pHead;
while(true)
{
pPrev = pSucc;
pSucc = pSucc -> pNext;
if(pSucc == NULL)
break;
if(d >= pSucc -> data)
break;
}
link *newLink = new link;
newLink -> data = d;
pPrev -> pNext = newLink;
newLink -> pNext = pSucc;
}
void linkList::display()
{
link *current = pHead;
while (current != NULL)
{
cout << current -> data << endl;
current = current -> pNext;
}
}
int main ()
{
int input;
linkList numbers;
cin >> input;
while(input >= 0)
{
cout << "Enter any numbers" << endl;
cin >> input;
numbers.add_Item(input);
}
numbers.display();
return 0;
}
I wrote this program which should take the numbers entered and sort them
out. It doesn¹t matter what order, if decreasing or increasing.
I guess I'm confused in the sorting part. Anyone has any advices??
#include <iostream>
using namespace std;
struct link
{
int data;
link *pNext;
link *pHead;
link *current;
};
class linkList
{
private:
link *pHead;
public:
linkList()
{ pHead = NULL;}
void add_Item(int d);
void display();
};
void linkList::add_Item(int d)
{
link *pPrev;
link *pSucc;
pPrev = pHead;
while(true)
{
pPrev = pSucc;
pSucc = pSucc -> pNext;
if(pSucc == NULL)
break;
if(d >= pSucc -> data)
break;
}
link *newLink = new link;
newLink -> data = d;
pPrev -> pNext = newLink;
newLink -> pNext = pSucc;
}
void linkList::display()
{
link *current = pHead;
while (current != NULL)
{
cout << current -> data << endl;
current = current -> pNext;
}
}
int main ()
{
int input;
linkList numbers;
cin >> input;
while(input >= 0)
{
cout << "Enter any numbers" << endl;
cin >> input;
numbers.add_Item(input);
}
numbers.display();
return 0;
}