1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Yuki888 [10]
3 years ago
13

Write a program, named sortlist, that reads three to four integers from the command line arguments and returns the sorted list o

f the integers on the standard output screen. You need to use strtok() function to convert a string to a long integer. For instance,
Computers and Technology
1 answer:
yawa3891 [41]3 years ago
7 0

Answer:

In C++:

void sortlist(char nums[],int charlent){    

   int Myarr[charlent];

const char s[4] = " ";  

char* tok;  

tok = strtok(nums, s);  

int i = 0;  

while (tok != 0) {  

 int y = atoi(tok);

 Myarr[i] = y;

 tok = strtok(0, s);  

 i++;

}  

int a;  

for (int i = 0; i < charlent; ++i) {

for (int j = i + 1; j < charlent; ++j) {

 if (Myarr[i] > Myarr[j]) {

  a =  Myarr[i];

  Myarr[i] = Myarr[j];

  Myarr[j] = a;

       }   }  }

 

for(int j = 0;j<charlent;j++){ printf(" %d",Myarr[j]); }  

}

Explanation:

This line defines the sortlist function. It receives chararray and its length as arguments

void sortlist(char nums[],int charlent){    

This declares an array

   int Myarr[len];

This declares a constant char s and also initializes it to space

const char s[4] = " ";  

This declares a token as a char pointer

char* tok;

This line gets the first token from the char

tok = strtok(nums, s);

This initializes variable i to 0

int i = 0;

The following while loop passes converts each token to integer and then passes the tokens to the array  

<em> while (tok != 0) {  </em>

<em>  int y = atoi(tok); </em><em>-> Convert token to integer</em><em> </em>

<em>  Myarr[i] = y; </em><em>-> Pass token to array</em><em> </em>

<em>  tok = strtok(0, s); </em><em>-> Read token</em><em> </em>

<em>  i++; </em>

<em> }  </em>

Next, is to sort the list.

int a;

This iterates through the list  

for (int i = 0; i < charlent; ++i) {

This iterates through every other elements of the list

for (int j = i + 1; j < charlent; ++j) {

This condition checks if the current element is greater than next element

 if (Myarr[i] > Myarr[j]) {

If true, swap both elements

<em>   a =  Myarr[i]; </em>

<em>   Myarr[i] = Myarr[j]; </em>

<em>   Myarr[j] = a; </em>

       }   }  }

The following iteration prints the sorted array

<em>for(int j = 0;j<charlent;j++){ printf(" %d",Myarr[j]); }  </em>

}

<em>See attachment for illustration of how to call the function from main</em>

Download cpp
You might be interested in
Write an algorithm to calculate the multiple of 5<br>​
Sauron [17]

Answer:

Multiples of 5 are 5, 10, 15, 20, 25,...

6 0
3 years ago
Carlos owns a hardware store. He currently is not using any software to track what he has in the store. In one to two sentences,
gladu [14]
Excel Would be good for inventory and price management
7 0
3 years ago
Read 2 more answers
for what reason do some security professionals consider insiders more dangerous than outside intruders?
dmitriy555 [2]
Truthfully,
 I think they trust the people where they originally came from than different people!!!!
8 0
3 years ago
Please list the computer data hierarchy from bit to database
vladimir2022 [97]

Answer:

 Data hierarchy is basically define to the data which is organized in the systematic manner. The main concept of the data hierarchy is to check the basic structure of the data. It basically involve the fields records and files for the data organization.

The following is the list of the computer data hierarchy from nit to address are:

1) Bit: It is the smallest unit of the data.

2) Field: The collection of all the characters in the data is known as field.

3) Record: The collection of the different fields is known as records.

4) File: The collection of various types of records in the database is known as file.

8 0
3 years ago
Hey system has defined specific Quetion that describe how signals are sent over connections. Which layer of the transmission con
ella [17]

Complete Question:

A system has defined specifications that describe how signals are sent over connections. Which layer of the Transmission Control Protocol/Internet Protocol (TCP/IP) model provides this function?

Group of answer choices.

A. Transport

B. Network

C. Data link

D. Physical

Answer:

A. Transport

Explanation:

Transmission Control Protocol/Internet Protocol (TCP/IP) model is a standard communication protocol used for interconnecting network devices such as routers, switches, host computers and access points over the internet.

A system has defined specifications that describe how signals are sent over connections. The layer of the Transmission Control Protocol/Internet Protocol (TCP/IP) model that provides these functions is the transport layer.

The transport layer comprises of two (2) standard protocols and these are TCP and UDP.

TCP is an acronym for Transmission Control Protocol and it is one of the essential and important protocol of the internet protocol network. This simply means that, it is an essential part of the TCP/IP network. The TCP has a wide range of applications in the following areas, file transfers, world wide web, remote administration, e-mail, etc.

The TCP connection are mainly established in the network using the three-way handshake.

UDP is an acronym for user datagram protocol and it enables the transfer or exchange of data between network devices.

3 0
3 years ago
Other questions:
  • What devices are used to connect computers to a network?
    10·1 answer
  • . Which one of the following is not a typical engine cylinder arrangement? A. V-type B. Dome-type C. In-line D. Horizontally opp
    13·1 answer
  • Write algorithm to find (a+b)^2=(a+b)*(a+b)​
    9·1 answer
  • What do developers do to support software products
    14·1 answer
  • Write a program that asks the user for a number in the range of 1 through 7. The program should display the corresponding day of
    7·1 answer
  • When actual hardware, network, and system software components are acquired and installed, they make up a(n) ____ for one or more
    14·1 answer
  • Always place the smallest dimensions ____ the object, with ____ the object.
    9·1 answer
  • SimpleScalar is an architectural simulator which enables a study of how different pro-cessor and memory system parameters affect
    6·1 answer
  • Makayla is cre iting a brochure for her computer consulting company. She designed the layout and placed a banner containing the
    6·1 answer
  • Slack how to enable direct message to outside workspace
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!