Hi, I created an array of numbers which converts into letters through a number generator. I need help sorting my array letters[j] so that the output can be printed in alphabetical order. After, I am storing it in a Linked List and printing it out. So far, it just prints out in different orders. Please help!
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
struct nodeType
{
int info;
nodeType *link;
};
void createList(nodeType*& first, nodeType*& last);
//void alphasort (nodeType*& first, nodeType*& last);
//void printList(nodeType*& first);
int main()
{
nodeType *first, *last;
createList(first,last);
// alphasort(first,last);
// printList(first);
system ("PAUSE");
return 0;
}
void createList(nodeType*& first, nodeType*& last)
{
srand(time(NULL));
int numbers[50];
int count = 0;
int i = 0 ;
int random;
int lowest;
char letters[50];
while(count < 50)
{
random = rand() % 90+65;
if(random >= 65 && random <= 90 || random >= 97 && random <= 122)
{
numbers[i] = random;
count++;
i++;
}
}
for(int j = 0; j < 50; j++)
{
letters[j] = numbers[j];
nodeType *newNode;
first = NULL;
last = NULL;
if (letters[j] < numbers[j])
letters[j] = lowest;
newNode = new nodeType;
newNode->info = numbers[j];
newNode->link = NULL;
if (first == NULL)
{
first = newNode;
last = newNode;
}
else
{
last->link = newNode;
last = newNode;
}
nodeType *current;
current = first;
while (current != NULL)
{
cout <<char(current->info)<<endl;
current = current->link;
}
}
}