Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

[C++] Help with array sorting and ASCII code scanning

linked list array ascii

  • Please log in to reply
1 reply to this topic

#1 Tonchi

Tonchi

    Helping the world with programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1249 posts
  • Location:Zagreb
  • Programming Language:C#, Others
  • Learning:C, C++, Python, JavaScript, Transact-SQL, Assembly

Posted 15 May 2012 - 03:21 PM

Hello guys. I need some help. I'm not such in C++ like in C# and I will never be because I'm not so interested in that language but I need to do this task. So I will appreciate your help very much.
This is the text of task:


User enters N integers, N <= 40. Numbers need to be sorted ascending.
Result must be provided by linked list. After sorting, it's necessary
to check if there is numbers which is in range of ASCII code of letters and if does program
needs to write out so as the letters. Also it's neccesary to split letters in uppercase and lowercase
letters in special (self) fields, after that arrays needs to be sorted descending using sorting by replacement and
bubble sort in that order. Algorithm must be realised by function.

I know that I'm a big noob in C++ so I will appreciate your help.
  • 0

Microsoft Student Partner, Microsoft Certified Professional


#2 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 15 May 2012 - 06:56 PM

Hey Tonchi, I assumed you as you are devoted to learning.

What are your the arguments you have not to learn C++?

About your problem, first of all, this is a homework for you, right? We are not here to do your homework for you but we'll help you to learn the things so that you can do your homework (as an experienced user, perhaps you can understand that) . Second, there is a 'Homework' section on the homepage (I guess you know that too being an experienced user), try to remember to post your homework on that section from next time. Last, try to learn the following things and solve your problem. Perhaps I'll show some segment of code for a particular step too so that you don't need to do googling for that.

Step 1: First you need to know how to write a 'Hello C++ World!' program in C. It is as following.
#include <iostream>
int main()
{
     std::cout << "Hello C++ World!"; // this line will print to the console
     return 0;
}


Step 2: You need to know how to take an integer input from user.

#include <iostream>
int main()
{
     std::cout << "Please provide an integer input"; // this line will print to the console
     int userInput;
     std::cin >> userInput; // this line will take input from user
     return 0;
}


Step 3: Now you need to know how to create a linked list. I think you already know what 'linked list' is. However you can refresh your memory from here -- http://en.wikipedia....ki/Linked_list. You also need to know about 'Pointer' -- http://www.cplusplus...rial/pointers/.

#include <iostream>

typedef struct LinkedListNode {
int value;
struct LinkedListNode *next;
};

void createASampleLinkedListOfThreeNodes()
{
//create first/root node
LinkedListNode* root = new LinkedListNode();
std::cin >> root->value; // take input integer for first/root node

// create second node
LinkedListNode* second = new LinkedListNode();
std::cin >> second->value; // take input integer for second node
// linked second node to first/root node.
root->next = second;


// create third node
LinkedListNode* third = new LinkedListNode();
std::cin >> third->value; // take input integer for third node
// linked third node to second node.
second->next = third;
// nake third to point to nothing (NULL).
third->next = 0;
}

int main()
{
     createASampleLinkedListOfThreeNodes();
     return 0;
}



Step 4: In this step, you need to know how to traverse the 'Linked List'. http://en.wikipedia....iki/Linked_list -- in this link you will see how to traverse a linked list (see section 'Singly linked lists'). Following is the code that you can use to traverse your linked list.

void traverseLinkedList()
{
    LinkedListNode *node = root;
    while(node != 0) {
         int intValue = node->value; // here is your integer value
         node = node->next;
    }
}

Remaining things: To print your integer value (if it falls in the characters ascii range) to characters as follows.

int iValue = root->value;
if ((iValue >= 65 && iValue <= 90) || (iValue >= 97 && iValue <= 122))
       std::cout << (char)iValue;

I think you can do the other logic parts like bubble sorting and reversing. However, we can help you on those parts too if you face problem. I think you will be able to create a linked list with taking integers input from user and be able to print it by traversing the linked list. If you are able to do that, your can post your problem here you face with remaining parts.
  • 0





Also tagged with one or more of these keywords: linked list, array, ascii

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download