Click here to Skip to main content
15,922,533 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Hide/Remove the Application Icon in the Title bar icon for a dialog with Border - Resizing. Pin
beko27-Jul-08 23:24
beko27-Jul-08 23:24 
GeneralRe: Hide/Remove the Application Icon in the Title bar icon for a dialog with Border - Resizing. Pin
Priya_Sundar28-Jul-08 0:57
Priya_Sundar28-Jul-08 0:57 
GeneralRe: Hide/Remove the Application Icon in the Title bar icon for a dialog with Border - Resizing. Pin
beko28-Jul-08 2:13
beko28-Jul-08 2:13 
QuestionWin 32 DLL using VC++ .Net Pin
rp_suman27-Jul-08 18:19
rp_suman27-Jul-08 18:19 
AnswerRe: Win 32 DLL using VC++ .Net Pin
Nibu babu thomas27-Jul-08 19:02
Nibu babu thomas27-Jul-08 19:02 
QuestionExcel automation problem Pin
followait27-Jul-08 16:32
followait27-Jul-08 16:32 
AnswerRe: Excel automation problem Pin
Yajnesh Narayan Behera27-Jul-08 18:33
Yajnesh Narayan Behera27-Jul-08 18:33 
QuestionSorting Algorithm for C++ for an array Pin
Princess Angel27-Jul-08 16:30
Princess Angel27-Jul-08 16:30 
My program must place words in alphabetical order and print the lines that each word appears on. So if "a" appears twice on line 1, once on line 2, and 3 times on line 3. The output should read: a: 1 1 2 3 3 3.

So I need help in coming up w/ a sorting algorithm that does this. Can someone one please help me?


This is my code:

// Example of Binary Search of an Array
#include <iostream>
#include <cstdlib>
#include <string>
#include "queue.h"
#include <sstream> // for istringstream


using namespace std;

const int MAX = 200; // maximum number of nodes
typedef string TreeItemType;
/*
class TreeNode { // node in the tree
private:
TreeNode();
TreeNode(const TreeItemType& nodeItem,
int left, int right);

TreeItemType item; // data portion
int leftChild; // index to left child
int rightChild; // index to right child

// friend class - can access private parts
friend class BinaryTree;
}; // end class TreeNode

//int values[] = { -23, -6, 10, 15, 20, 25, 32, 40, 55, 82, 90, 100 };
TreeNode values[MAX];

*/

typedef struct dictType{
string str;
Queue line;
}dictItemType;
const string Punctuation = ",.;:?\"'!@#$%^&*[]{}|";


int main () {
//int sizeValues = sizeof(values) / sizeof (int);
istringstream strLine;
string line, word;
//dictItemType dict;
dictItemType dictionary[200];
int currentLine=0;
int j;
while (getline(cin,line)) {
++currentLine;

// clear the strstream and copy the entered line to it
strLine.clear();
strLine.str(line);

// now get each word-sequence from the strLine stream

while (strLine >> word){
//dictionary[i].str = word;

//You need tokenized.
while (word.length() > 0 && Punctuation.find(word[0]) != string::npos)
word = word.substr(1);

for( j=0; j < MAX; j++){
if(dictionary[j].str.empty()){
cout << currentLine << ": " << word << endl;
dictionary[j].str = word;
dictionary[j].line.enqueue(currentLine);
break;
}else{
if(dictionary[j].str.compare(word) == 0){
cout <<"Already there"<<endl << currentLine << ": " << word << endl;
dictionary[j].line.enqueue(currentLine);
break;
}//endif
}//endifelse
}//endfor
//j=0;
}//endwhile
}//endwhile

//SORTALGORITHM



// ********************************************************
// Header file queue.h - Pointer-based implementation.
// ********************************************************

typedef int QueueItemType;

class Queue {
public:
// constructors and destructor:
Queue(); // default constructor
~Queue(); // destructor

// Queue operations:
bool isEmpty();
// Determines whether the queue is empty.
// Precondition: None.
// Postcondition: Returns true if the queue is empty;
// otherwise returns false.

void enqueue(QueueItemType newItem);
// Inserts an item at the back of a queue.
// Precondition: newItem is the item to be inserted.
// Postcondition: If the insertion is successful, newItem
// is at the back of the queue.

bool dequeue();
// Dequeues the front of a queue.
// Precondition: None.
// Postcondition: If the queue is not empty, the item
// that was added to the queue earliest is deleted
// and returns true; if queue is empty, returns false

bool dequeue(QueueItemType& queueFront);
// Retrieves and deletes the front of a queue.
// Precondition: None.
// Postcondition: If the queue is not empty, queueFront
// contains the item that was added to the queue
// earliest, and the item is deleted and returns
// true; if queue is empty, returns false

bool getFront(QueueItemType& queueFront);
// Retrieves the item at the front of a queue.
// Precondition: None.
// Postcondition: If the queue is not empty, queueFront
// contains the item that was added to the queue
// earliest and returns true; if queue is empty,
// returns false

private:
// The queue is implemented as a linked list
// with one external pointer to the front of the queue
// and a second external pointer to the back of the
// queue.
struct QueueNode {
QueueItemType item;
QueueNode *next;
}; // end struct

QueueNode *backPtr;
QueueNode *frontPtr;
}; // end class


// *************************************************************
// Implementation file queue.cpp - Pointer-based implementation
// *************************************************************
#include "queue.h" // header file

Queue::Queue() {
backPtr = frontPtr = NULL;
} // end default constructor

Queue::~Queue() {
while (!isEmpty())
dequeue();
} // end destructor

bool Queue::isEmpty() {
return backPtr == NULL;
} // end isEmpty

void Queue::enqueue(QueueItemType newItem) {
// create a new node
QueueNode *newPtr = new QueueNode;

// set data portion of new node
newPtr->item = newItem;
newPtr->next = NULL;

// insert the new node
if (isEmpty()) // insertion into empty queue
frontPtr = newPtr;
else // insertion into nonempty queue
backPtr->next = newPtr;

backPtr = newPtr; // new node is at back
} // end enqueue

bool Queue::dequeue() {
if (isEmpty()) return false;

// queue is not empty; remove front
QueueNode *tempPtr = frontPtr;
if (frontPtr == backPtr) { // special case?
// yes, one node in queue
frontPtr = NULL;
backPtr = NULL;
}
else frontPtr = frontPtr->next;

tempPtr->next = NULL;
delete tempPtr;
return true;
} // end dequeue

bool Queue::dequeue(QueueItemType& queueFront) {
if (isEmpty()) return false;
// queue is not empty; retrieve front
queueFront = frontPtr->item;
dequeue(); // delete front
return true;
} // end dequeue

bool Queue::getFront(QueueItemType& queueFront) {
if (isEmpty()) return false;
// queue is not empty; retrieve front
queueFront = frontPtr->item;
return true;
} // end getFront
// End of queue.cpp

Princess Angel

AnswerRe: Sorting Algorithm for C++ for an array Pin
CPallini27-Jul-08 21:38
mveCPallini27-Jul-08 21:38 
Questiondesignated initializer Pin
kcynic27-Jul-08 16:07
kcynic27-Jul-08 16:07 
AnswerRe: designated initializer Pin
Joe Woodbury27-Jul-08 16:22
professionalJoe Woodbury27-Jul-08 16:22 
QuestionADO .NET using c++ Pin
rp_suman27-Jul-08 15:51
rp_suman27-Jul-08 15:51 
AnswerRe: ADO .NET using c++ Pin
CPallini27-Jul-08 21:23
mveCPallini27-Jul-08 21:23 
QuestionI can build but cant run my program... Pin
xelios27-Jul-08 9:20
xelios27-Jul-08 9:20 
AnswerRe: I can build but cant run my program... Pin
hoxsiew27-Jul-08 15:41
hoxsiew27-Jul-08 15:41 
QuestionLinked List nodes don't recognise "Tile" (data) class. Pin
Sauce!27-Jul-08 3:05
Sauce!27-Jul-08 3:05 
AnswerRe: Linked List nodes don't recognise "Tile" (data) class. Pin
Luc Pattyn27-Jul-08 3:24
sitebuilderLuc Pattyn27-Jul-08 3:24 
GeneralRe: Linked List nodes don't recognise "Tile" (data) class. Pin
Sauce!27-Jul-08 3:31
Sauce!27-Jul-08 3:31 
GeneralRe: Linked List nodes don't recognise "Tile" (data) class. Pin
Luc Pattyn27-Jul-08 3:38
sitebuilderLuc Pattyn27-Jul-08 3:38 
GeneralRe: Linked List nodes don't recognise "Tile" (data) class. Pin
Cedric Moonen27-Jul-08 8:50
Cedric Moonen27-Jul-08 8:50 
GeneralRe: Linked List nodes don't recognise "Tile" (data) class. Pin
Sauce!27-Jul-08 15:46
Sauce!27-Jul-08 15:46 
QuestionTrouble with Releaser Version - Double selections in List Control = DOES NOT happen in Debug version Pin
Larry Mills Sr26-Jul-08 15:46
Larry Mills Sr26-Jul-08 15:46 
AnswerRe: Trouble with Releaser Version - Double selections in List Control = DOES NOT happen in Debug version Pin
Luc Pattyn26-Jul-08 16:05
sitebuilderLuc Pattyn26-Jul-08 16:05 
GeneralRe: Trouble with Releaser Version - Double selections in List Control = DOES NOT happen in Debug version Pin
Larry Mills Sr28-Jul-08 10:04
Larry Mills Sr28-Jul-08 10:04 
GeneralRe: Trouble with Releaser Version - Double selections in List Control = DOES NOT happen in Debug version Pin
Luc Pattyn28-Jul-08 10:17
sitebuilderLuc Pattyn28-Jul-08 10:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.