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
Naddika [18.5K]
3 years ago
7

Write a function that will alphabetize a string WITHOUT using the sort function :

Computers and Technology
1 answer:
Dimas [21]3 years ago
7 0

Answer:

here is code in C++.

#include <bits/stdc++.h>

using namespace std;

// function to alphabetize the input string

void alphabetize(string &str)

{

// find the length of string

 int n=str.size();

 

  for(int x=0;x<n;x++){

      for(int y=x+1;y<n;y++)

      {  

          //swap the character

          if(str[x]>str[y]){

              char ch=str[x];

              str[x]=str[y];

              str[y]=ch;

          }

      }

  }

 

  cout<<"alphabetize string is: "<<str<<endl;;

 

}

int main()

{// string variable to read input

  string inp;

 

  cout<<"Please Enter a String in lowercase :";

  //reading the input

  cin>>inp;

  // call function with inp argument

  alphabetize(inp);

  return 0;

  }

Explanation:

Declare a variable "inp" of string type and assign the input string to it. call the alphabetize() function with argument "inp".In the alphabetize(),find the length  of input string.Then travers the string and if a character is greater than any  next character in the string then swap it, so that all the character are sorted.

Output:

Please Enter a String in lowercase :helloworld                                                                                                                

alphabetize string is: dehllloorw

You might be interested in
In an office there is a unisex bathroom with n toilets. The bathroom is open to both men and women, but it cannot be used by men
Gnesinka [82]

Answer:

Check the explanation

Explanation:

#include <stdio.h>

#include <stdlib.h>

#include <pthread.h>

#include <semaphore.h>

int mcount,wcount;

sem_t x,y,z,wsem,msem,cap;

void delay(void)

{

int i;

int delaytime;

delaytime = random();

for (i = 0; i<delaytime; i++);

}

void *woman(void *param)

{

sem_wait(&z);

sem_wait(&wsem);

sem_wait(&y);

wcount++;

if(wcount==1)

{ sem_wait(&msem); }

sem_post(&y);

sem_post(&wsem);

sem_post(&z);

sem_wait(&cap);

printf("woman in!\n");

delay();

printf("\twoman out!\n");

sem_post(&cap);  

sem_wait(&y);

wcount--;

if(wcount==0)

{ sem_post(&msem); }

sem_post(&y);

}

void *man(void *param)

{  

sem_wait(&z);

sem_wait(&msem);

sem_wait(&x);

mcount++;

if(mcount==1)

{ sem_wait(&wsem); }

sem_post(&x);

sem_post(&msem);

sem_post(&z);

sem_wait(&cap);

printf("\t\tman in!\n");

delay();

printf("\t\t\tman out!\n");

sem_post(&cap);

sem_wait(&x);

mcount--;

if(mcount==0)

{sem_post(&wsem);}

sem_post(&x);

}

int main(void)

{

int i;

srandom(60);

mcount = 0;

wcount = 0;

sem_init(&x,0,1); // for sem_init, initial value is 3rd argument

sem_init(&y,0,1);

sem_init(&z,0,1);

sem_init(&wsem,0,1);

sem_init(&msem,0,1);

sem_init(&cap,0,4); // eg. cap initialized to 4

pthread_t *tid;

tid = malloc(80*sizeof(pthread_t));

// You can use your cobegin statement here, instead of pthread_create()  

// I have forgone the use of pthread barriers although I suppose they would nicely imitate the functionality of cobegin.

// This is merely to retain simplicity.

for(i=0;i<10;i++)

{

pthread_create(&tid[i],NULL,woman,NULL);

}

for(i=10;i<20;i++)

{  

pthread_create(&tid[i],NULL,man,NULL);

}

for(i=0;i<20;i++)

{  

pthread_join(tid[i],NULL);

}

return(0);

}

5 0
3 years ago
Help me please with this
LUCKY_DIMON [66]

Answer:

Explanation:

QUestion 2 is A

QUestion 1 is A i think

7 0
2 years ago
Changing the configuration of a database falls under which category of databaseâ administration?
harkovskaia [24]
Changing the configuration of a database falls under which category of databaseâ administration?

d. operation
8 0
2 years ago
A school principal trying to find out if parents will help buy new playground equipment shows digital leadership by.
ELEN [110]

Answer:

D. is the correct answer!

8 0
3 years ago
Read 2 more answers
Can someone help me with this
Alex787 [66]
I’m not sure but I think it belongings.
5 0
2 years ago
Other questions:
  • Windows explorer has a pane located on the left side which can display the directory structure of one or more drives. what is th
    15·1 answer
  • ______________ is only one of the marketing mix tools that acompany uses to achieve its marketing objectives.
    7·1 answer
  • nswer the following questions concerning chapter 1:1.1 Which pair of layers are NOT peer layers?a.Transport layer in the sender
    9·1 answer
  • To what type of user does he most likely have access? Jae is using a computer at the public library to do research she's able to
    9·1 answer
  • The access code for a? car's security system consists of fivefive digits. the first digit cannot be zerozero and the last digit
    13·1 answer
  • ITS MAKING ME TYPE URL CODES NOW!
    6·1 answer
  • Suppose that a computer can read or write a memory word in 5 nsec. Also suppose that when an interrupt occurs, all 32 CPU regist
    10·2 answers
  • In addition to the decimal number system, the number systems used most often in PLC operationand programming are ________.
    9·1 answer
  • True / False
    6·1 answer
  • Write a method named removeRange that accepts an ArrayList of integers and two integer values min and max as parameters and remo
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!