473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Bubble sort for anagrams/words

How do I correct the program below to search all the anagrams in a given file.

First, for each word, build another word (its key) with all its letters sorted. For instance, build "dorw" for "word", or "eelttr" for "letter".
Build an array of all the keys, and sort it using a bubble sort. I have to write a modified version of bubble sort that maintains also the array of the primary words.
For instance, if I had ["rude", "word", "dure", "from", "form", "letter"],
our initial array of keys would be:
["deru", "dorw", "deru", "fmor", "fmor", "eelttr"]
After the sort, we should have the keys as:
["deru", "deru", "dorw", "eelltr", "fmor", "fmor"]
and the words
["rude", "dure", "word", "letter", "from", "form"]

I need to go through the array of keys to find out duplicated keys, and the corresponding words. Or how can I do this with struct and arrays? Thanks in advance.

#include <iostream>
#include <fstream>

char** read(const char* fileName, int& count)
{
std::ifstream countingStream(fileName);
// first count them
count = 0;
while (true) {
char line[100];
countingStream.getline(line, 100);
if (strlen(line) == 0) {
break;
}
count += 1;
}
countingStream.close();
std::ifstream readingStream(fileName);
char** words = new char* [count];
for (int index = 0; index < count; ++index) {
char line[100];
readingStream.getline(line, 100);
words[index] = strdup(line);
std::cout << line << std::endl;
}
readingStream.close();
return words;
}
Oct 11 '06 #1
0 4400

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Gram | last post by:
Hello, Can anyone help out with a bubble sort for strings using ASP? I have a text file of words id like to sort and count. Thanks in advance for any help. Gram.
34
by: Mark Kamoski | last post by:
Hi-- Please help. I need a code sample for bubble sort. Thank you. --Mark
4
by: Chris | last post by:
I have a bubble sort for a 2-dimensional array that sorts a string,number pair based on the number. The code for the sort is as follows: Private Sub SortArray(ByRef roundarray(,) As String)...
4
by: Gaijinco | last post by:
I'm not quite sure why this code doesn't works: #include <iostream> #include <algorithm> #include <vector> #include <string> using namespace std; class word {
0
by: scruggsy | last post by:
Given a dictionary of words, and a phrase, I want to find all possible combinations of words such that their letters form an anagram of the phrase. For instance: Words: STACK, STICK, I, LIE, ALE,...
2
by: sonali deshpande | last post by:
hi, i have newly started with C programming.i have been trying a lot for bubble sort. i want a program that takes words as input and then outputs them alphabetically. plz help!! thanx in advance
12
by: midknight5 | last post by:
Hello everyone, I am familiar with a normal bubble sort when dealing with an array of number but I am unsure as how to implement a sort when I have an array that is filled with classes which hold...
7
by: mahdiahmadirad | last post by:
Hi dears! I wrote a simple bubble sort algorithm. it works properly when we compare full arrays but i want to sort a 2d array according to a specific part of array. it has some problem to swapping...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.