473,396 Members | 1,766 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,396 software developers and data experts.

STL, Priority Queues, Help and Assitance.

J.
Hello all,

I need some assistance. I've been out of the C++ game way too long and
I need some help getting back up to speed. I'm taking a class where STL
is mostly covered...I know alot of people break off the message here,
but I want help and guidance to understand, not someone to do my work.
Asking for help is a respectable thing, it's when you admit to yourself
that you can't do it alone.

I think I might be a little over my head, but I've been doing a lot of
studying to bring myself back up to speed. I understand all the
concepts, it's just implementing them...that's where my problem lies.

Here is what I am working on. I have an interface file (database.h) and
an implementation file (database.cpp). From what I understand, the
header file is complete.

I don't even know where to start here. You guidance is appreciated, I'm
just trying to learn.

/************** database.h **************/
#ifndef DATABASE_H
#define DATABASE_H

#include <queue>
#include <vector>
#include <fstream>
#include <iostream>

// Database of items
// sizeType is defined as typedef std::size_t sizeType; in other file

namespace myNamespace {

template <class Item>
class database {
public:
database ( );
~database ( ) {file.close ( );}

sizeType print ( );
sizeType removeAll ( );

sizeType add (Item &);
Item search (sizeType);
Item remove (sizeType);
protected:
std::fstream file;

// if used == 0; file is empty.
// if used > 0, file has items at positions
// from 0 to used - 1, some of which
// may have been removed.
sizeType used;

// positions of removed items
std::priority_queue<sizeType, std::vector<sizeType>,
std::greater<sizeType> > removedPos;

database (const database &); // can not copy database
void operator = (const database &); // can not assign database
};

}

#include "database.cpp"
#endif

/************** database.cpp **************/
// implementation file for database.h

namespace myNamespace
{

template <class Item>
database<Item>::database () : used (0)
{
file.open ("_temp", std::ios::in
| std::ios::out
| std::ios::binary);
if (!file)
std::cout << " Can not open database file\n";
}

template <class Item>
sizeType database<Item>::add (Item &item)
{
//Add item to file and return position at which item
//is added. If removedPos is empty, add item as last item;
//else add item at position at head of removedPos.
}

template <class Item>
Item database<Item>::search (sizeType pos)
{
//Return item at position. Assume item at the
//position has not been removed.
}

template <class Item>
Item database<Item>::remove (sizeType pos)
{
//Add position to removedPos and return item at position.
//Assume item at the position has not been removed. This
//creates a hole in the file.
}
template <class Item>
sizeType database<Item>::print ( )
{
//Print items that have not been removed and return
//the number of printed items.
}

template <class Item>
sizeType database<Item>::removeAll ( )
{
//Remove all items and return number of removed items
}

}

Nov 17 '05 #1
0 1285

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: aaronwmail-usenet | last post by:
I've been wondering about benchmarks recently. What is a fair benchmark? How should benchmarks be vetted or judged? I decided to see what you folks thought, so for discussion I compared two...
38
by: Aaron W. LaFramboise | last post by:
Hello, I understand that an easy way to make the standard std::priority_queue stable is by including an integer stamp with each node that is incremented each time a new node is pushed into the...
6
by: Der Andere | last post by:
Are priority queues implemented in the STL in Visual Studio 6? If no, which is the easiest way to simulate them? Multisets? BTW: The container contains pointers to instances of a class. The...
1
by: Der Andere | last post by:
I posted this reaction in a thread quite far below so I fear people won't read it. I got stuck now for quite a while and just don't know what to try else. Thanks, Matthias > > Are priority...
1
by: Jim Strathmeyer | last post by:
So, I've been looking for a wrapper class for STL priority queues, and haven't been able to find one. (Websearching for info about the STL sure shows how much it's changed over the past few years.)...
5
by: Dan H. | last post by:
Hello, I have implemented a C# priority queue using an ArrayList. The objects being inserted into the priority queue are being sorted by 2 fields, Time (ulong) and Priority (0-100). When I...
3
by: eric.boissard | last post by:
Hello, I managed to implement the AStar algorithm, however I have some trouble using the priority queue, and the 'compare' function. Here is my 'Waypoint.h' header file: class Waypoint {...
8
by: vidishasharma | last post by:
Can somebody suggest good URL which contains code for merging of 2 or more priority queues in c#.
5
by: kidfiction | last post by:
Hello again, I was wondering if you could make priority queues with defined compare functions out of structs rather than objects. Currently I have this (with some things omitted: bool...
1
by: operatingsystem | last post by:
I need to generate such scheduler in operating system subject which satisfy below conditions...may i request u if anybody knows abt this plz help me out in this..topics.. Scheduler...
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:
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
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.