Sorting a list of strings


This program I made is in c++ and uses Template libraries for strings and list.

The program is:

#include<iostream>
#include<string>
#include<list>
using namespace std;
int main(){
list<string> a;
string b="1";
cout<<"Enter the strings to be sorted and end it with '0'..\n";
while(b!="0"){
cin>>b;
a.push_back(b);
}
a.sort();
list::iterator i;
for(i=a.begin();i!=a.end();++i){
cout<<*i<<"\n";
}
return 0;
}


The program uses a list to store the inserted strings and then iterate over the list to display the required list.

Hope the program is clear…

Advertisements
Explore posts in the same categories: C++

Tags: , , , ,

You can comment below, or link to this permanent URL from your own site.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: