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 a deisgn project, what two types of graphics or images is the digital artist respondsible for creating?
Inga [223]
Vector and raster images
7 0
3 years ago
What is a digital pen called<br><br>A digital pen is called a ____
steposvetlana [31]
A digital pen is a battery-operated writing instrument that allows the user to digitally capture a handwritten note or drawing. Typically, a digital pen comes with a Universal Serial Bus (USB) cradle to let the user upload the handwritten notes to a personal computer (PC).

Sometimes called a smart pen or stylus.
4 0
3 years ago
Read 2 more answers
How do i win Mine Craft
Vlad [161]
Answer: defeat the dragon? I think
3 0
3 years ago
Read 2 more answers
How do i beat the wolf-sheep-cabbage game?<br> (it's a extra credit thing on my hw)
dolphi86 [110]
I use random buttons try that if not send me a link ill help
3 0
3 years ago
Ark titanoboa taming
ivann1987 [24]
Huh???????................
3 0
3 years ago
Other questions:
  • Name one app that currently has a positive impact on society and explain why you think it has had a positive effect.
    10·1 answer
  • Boolean expressions are named after ____
    9·1 answer
  • A user has just reported that he downloaded a file from a prospective client using IM. The user indicates that the file was call
    11·1 answer
  • How many times would the following loop iterate?
    15·1 answer
  • The___is a waterproof fabric that is placed around your camera
    7·1 answer
  • Who has gotten a random file link from someone? What file does it contain?
    8·2 answers
  • Which list shows a correct order of mathematical operations that would be used by a spreadsheet formula?
    5·2 answers
  • Computer in education are used for teaching and learning aids​
    14·1 answer
  • True or False
    9·1 answer
  • NAT addresses concerns over the dwindling IPv4 address space by ___________________. 1 point allowing networks to use fewer IP a
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!