C++ :: Using STL Sort With Custom Classes?

Oct 8, 2013

I've written a doubly linked list per my assignment instructions. I've implemented begin() and end() iterators for it, and they work with no problems when traversing the list. However, I need to sort the elements in the list. We are allowed to use the sort function defined in the <algorithm> header since we haven't yet covered sorting algorithms.

But, I'm running into a ton of problems. I figured as long as the begin() and end() iterators were defined for the list, then sort(list.begin(), list.end(), compare) would do the trick. The main errors I'm getting are:

error: no type named iterator_category
error: no type named value_type
error: no type named difference_type
error: no type named pointer
error: no type named reference

And also errors for no match of the + and - operators for the iterator class.

I understand reference, pointer, and value_type, but I have no idea about iterator_category and difference_type. Additionally, I'm a little unsure why the + and - operators need to be overloaded.

View 8 Replies


ADVERTISEMENT

C# :: Creating Custom If Statement Classes?

Jun 19, 2014

I've been working on a project for a few days now, and within this project I need to have a class system that can function similarly to an if statement. The problem I'm having is I can't seem to find any good information on the order in which if statements process the information within it. I understand that if statements process whatever's in parenthesis first, but my question is that when their are several booleans of equal value, for example: "if(x == 1 && y == 2 || 3 == 4 && 4==6)", in what order does it process these true or false statements? (The actual content of the example is superfluous).

View 2 Replies View Related

C++ :: Sort Of Vector Of Custom Objects

Feb 23, 2014

I'm working on a code for ascertaining the minimum penalty of an assignment problem. The basic complication of my code is this: I have a vector of objects of a custom struct. The struct has a member, which is an integer. I need to keep the vector sorted according to that member, even when objects are added to or deleted from the vector. To illustrate the problem, I'll give an example.

Code:

typedef struct examplestruct{int i;
char c;
...} es;
int function(void)
{vector<es> ObjectTable;
//insert an object so that the vector remains sorted according to i
insertobject( newobject, &ObjectTable);
//deleting the top element of the vector
deleteobject(&ObjectTable);
return 0;}

I have tried to do it using bubblesort. But it's too slow. How to make a heap out of it.

The detailed premises of the problem is this: There are a number of jobs, and with each job a completion time and a cost coefficient. We are to ascertain the optimal sequence of jobs for which the penalty is minimum. Now, suppose we are given jobs A, B, C, D and E. We find out the lower bound of penalties for all the jobs.

Suppose we find B has the lowest penalty. Then we find out the lower bound of penalties for BA, BC, BD and BE. We continue this until we have the best value and a complete sequence. The way I have implemented this in a code: I have created two structs. One is Job, with the completion time and cost coefficient as members. The other is Node. Nodes have a Job Array and a Penalty as members. Now, we have a vector of Nodes which we need to keep sorted according to the penalty. We need to insert new Nodes and delete the expanded Nodes.

I have included my code. The pushInTable function inserts the new Nodes in a sorted vector. But it slows down remarkably when we give more than 20 jobs as input.

View 9 Replies View Related

C++ :: Custom Linked List Sort Method

Apr 3, 2013

I am making a custom linked list (for fun!) and want to implement a sort method that sorts the stored data using the stored types > and < operators (will require the type to have these operators overloaded)

What is the best way to do this? I guess the first thing one might jump to would be to compare the current node with the the node to its "right" see if one is greater than the other. Then keep iterating through the list until you don't swap any more nodes. However I am thinking there is probably a more efficient way to do this. Here is my code so far:

#ifndef LIST_HPP
#define LIST_HPP
#include <string>

[Code].....

Surely there is a way to sort with only one iteration through the list?

View 2 Replies View Related

C++ :: Array Of Classes With Classes Inside

Oct 5, 2013

I have an array of (Student)classes created in Manager.h, which contains a new instance of class Name (name),(in Student.h)How would I go about accessing the SetFirstName method in Name.cpp if I was in a class Manager.cpp? I have tried using Students[i].name.SetFirstName("name");

// In Manager.h
#include"Student.h"
class Manager
{

[Code]....

View 2 Replies View Related

C :: Radix Sort Function To Sort Array Of 64 Bit Unsigned Integers

Aug 19, 2013

Example radix sort function to sort an array of 64 bit unsigned integers. To allow for variable bin sizes, the array is scanned one time to create a matrix of 8 histograms of 256 counts each, corresponding to the number of instances of each possible 8 bit value in the 8 bytes of each integer, and the histograms are then converted into indices by summing the histograms counts. Then a radix sort is performed using the matrix of indices, post incrementing each index as it is used.

Code:
typedef unsigned long long UI64;
typedef unsigned long long *PUI64;
PUI64 RadixSort(PUI64 pData, PUI64 pTemp, size_t count) {
size_t mIndex[8][256] = {0};
/* index matrix */
PUI64 pDst, pSrc, pTmp;
size_t i,j,m,n;
UI64 u;

[Code]....

View 9 Replies View Related

C++ :: How To Sort A 1D Array Using Function Sort

Mar 22, 2013

how to sort a 1D array using function sort().but if i have a 2D array how do i sort only 1 row of it (or column)?

View 2 Replies View Related

C/C++ :: Bubble Sort And Selection Sort?

Feb 19, 2014

You will write a program that uses a multidimensional array having 3 rows and 8 columns and sorts each of the rows using both a bubble sort and a selection sort.

You must declare the array inside of main. You will have a for loop containing the calls to bubbleSort and selectionSort. You need to pass into function bubbleSort and selectionSort the following: 1) each column of the multidimensional array, 2) the size of the column, and 3) a particular row number of the multidimensional array to be used for printing out the "pass" shown on the following pages.

I keep getting an error that the identifier for bubbleSort and selectionSort is not found. (Error C3861) Also, I feel like I'm missing something in int main() to get it to sort properly.

# include <iostream>
using namespace std;
int main()
{

[Code].....

View 14 Replies View Related

C++ :: How To Build A Custom Allocator

Feb 7, 2014

I'm trying to write a custom allocator that I can use with the STL. Here's what I have so far :

Code:
#include <cstddef>
#include <iostream>
#include <memory>
#include <vector>
template<class T>
struct customallocator {

[Code].....

I'm doing and currently, my push_back doesn't seem to do anything.

View 12 Replies View Related

C++ :: Custom Vector Class

Oct 9, 2014

Let's say we have a custom Vector class and I need to know which of the following is considered to be more efficient and why of course.

Vector Vector::operator+(const Vector &b) const {
return Vector(x+b.x,y+b.y);
}

Vector Vector::operator+(const Vector &b) const {
Vector tmp(x+b.x,y+b.y);
return tmp;
}

View 1 Replies View Related

C++ :: Add Custom MENUITEM To A POPUP?

Jul 13, 2014

I have a POPUP

MAIN_MENU MENU {
POPUP "&Manager" {
MENUITEM "New Royal Python", MENU_NEW_ROYAL_PYTHON
POPUP "&Select Python" {
}
}
}

I basically want to give the POPUP an ID so I can talk with it but it does not seem to be accepting a second parameter. Once I have done that I need to send a message to it to ask it to add a new item, what are the messages I need to send for this?

View 8 Replies View Related

C++ :: Creating A Custom Filetype?

May 21, 2013

I am making a level editor that needs to output a custom map file for use with source code that I will write for a graphics library.

My question is: What do I need to bear in mind when deciding how to structure a custom file type? Also how can I encode a standard bitmap image into my file (the tile set) so that it can all be contained in a single file rather two files; the map file and tile set (.bmp file).

View 3 Replies View Related

C# :: Custom Button Shape (WPF)

Nov 30, 2014

I have begun switching from WinForms to WPF and I'm having a hard time understanding the new concepts. In WinForms, I had a few User Controls, custom drawn using shapes (rectangles, ellipses, etc). They had some unique properties, like "Flashing" (setting this property to True and setting the "Flash Interval" property to 500 would have resulted in the control changing its background color to white and back again, every 0.5 seconds), "Beeping", etc.

I have tried to replicate these controls in WPF/XAML and so far managed to draw the shape. However, when it came to implementing a custom property that would redraw the background color of the rectangle every interval set by user in another property, i got stuck. The property is being set, but it doesn't change the background color. Alternatively, i have tried this method, with the same results (i got it to show in the "Properties" window in Visual Studio, i can set it, it is being stored in XAML, but it doesn't affect the background.

C# code behind:
public struct LCARSColors
{
public static Brush DarkBlue = (Brush)(new BrushConverter().ConvertFrom("#FF3366CC"));
public static Brush LightBlue = (Brush)(new BrushConverter().ConvertFrom("#FF99CCFF"));
public static Brush Pink = (Brush)(new BrushConverter().ConvertFrom("#FFCC99CC"));

[Code] ....

If i use this line (commented in this code sample):

<!--<SolidColorBrush x:Name="MySolidColorBrush" Color="{DynamicResource DarkBlue}" />-->

The background is colored in DarkBlue (as defined). But if i use this line:

<SolidColorBrush x:Name="MySolidColorBrush" Color="{Binding BackgroundColor, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

Nothing happens, the rectangle disappears entirely. If i add this to the above line:

FallbackValue=LightYellow

The rectangle is colored in LightYellow, meaning that the property is not accepted and the fallback value is used. Why?

View 9 Replies View Related

C# :: How To Make Custom GUI Theme

Jul 12, 2014

I've done some research and found that people use Mah metro, though I don't want to use that because I want to make a GUI that is fully mine, so I can do what ever I want to customize it to my liking.

I don't know how to get this done in WinForms....

View 2 Replies View Related

C# :: Creating Custom Cursor In WPF?

May 26, 2014

I was going through tutorial in WPF on customs Cursor, While Running the application i am getting an exception XamlParseException was unhandled, here the code

public partial class MainWindow : Window
{
public MainWindow()
{

[Code].....

View 4 Replies View Related

C# :: Custom Control Properties?

Sep 23, 2014

I have been trying to make a custom control(list box with more features). I know how to setup custom properties, but how do I make it so that the property can be edited in a separate window ?

I think I figured out how to show the form itself, and I don't know how to make the [...] button like :

There's not much Custom Control tutorials out there, and that's really the problem here.

View 1 Replies View Related

C# :: XAML - How To Use Custom Image

Nov 9, 2014

I am new to application coding as I previously coded Python. XAML. How to use a custom image I made as a background image in my program. I have searched everywhere but all there is about how to use the asset images.

View 2 Replies View Related

C++ :: Sorting A Map By Custom Comparison?

Jan 8, 2012

so i have a std::map like this:

map<DWORD,DWORD> mymap;

now i want to sort it by the second DWORD value, and thus i have to implement my own comparison function and use sort() from <alogirthm>:

Code:
bool y(const map<DWORD,DWORD>::iterator& a, const map<DWORD,DWORD>::iterator& b)
{
if(a->second < b->second)
return 1;
else
return 0;
}
...
sort(mymap.begin(), mymap.end(),y);
...

but this throws thousands of errors at me, including C2784.

View 14 Replies View Related

C++ :: Custom Exceptions With Default Behaviour

May 24, 2013

I've been pondering which of these 2 approaches would make for the best interface for a library: Defining custom exceptions with specific names for different error scenarios but with standard behaviour, or simply using the predefined exceptions from the STL.

This is my current approach:
Code:
namespace rpp
{
class ConnectionError : public std::exception
{
public:
ConnectionError(const std::string &p_err);

[Code] .....

This seems to make for more descriptive code but it adds no functionality and the implementations are completely identical, which seems "off" to me, somehow.

View 8 Replies View Related

C++ :: Defining A Custom Arithmetic Type

Jun 26, 2014

I want to create an unsigned arithmetic type that can hold a maximum size of 360. Without having to create a method.

It should be in such a manner that:

Code:
typedef uint8_t radius;
radius rotation = 0;

radius foo (radius rotation)
{ return --rotation;
}

returns 359, instead of 255, or 65535 or whatever max value the type I base my type on can hold.

View 6 Replies View Related

C++ :: Using Custom Class For STL Set Data Structure

Oct 27, 2014

When we want to use custom classes for the STL set data structure, how to do it?

I look around and see people passing comparators, overloading operator(), and also overloading operator< in the class itself.

Which one's the idiomatic c++ way?

View 1 Replies View Related

C :: Implementing Custom Behaviour But Something Fails

Jan 2, 2015

I am creating a special struct with unknown functions. I use this approach:

Callbacks.h Code: #ifndef CALLBACKS
#define CALLBACKS
struct Callbacks;
struct Callbacks* getNewCallback();

[Code]....

When I ran it only the calls from doers array is called 7 times normally, and donters only one time. Why is that? When I call doers from the second loop, it prints the doers functions again....and only one call to donters is made to the first static inline donter functions __dont1()...

View 7 Replies View Related

C :: Creating Custom Audio Function

Apr 2, 2013

I'm trying to make a windows-focused , I will make it portable after , audio function that plays sounds according to my midi file. I know there is playsound, but it's not what I desire. I'm curious if Beep plays through the sound card or is similar to printf("a") ? I'm just looking for a low level solution.

View 1 Replies View Related

C++ :: Custom Array Class For A Project

Oct 15, 2014

I am currently working on a custom "Array" class for a project, and I have run into an error I don't quite understand the source of. The relevant code is as follows:

template<typename T> class Array {
private:
T errValCopy;
public:
T __errVal__;
uint16 __size__;
T* __ptr__;
Array(const T& errorValue);

[Code] ....

When I try to run the following code:

Array<Array<int>> a(Array<int>(-1));

The error log tells me there is no appropriate default constructor available. If I understand it correctly, "default constructor" refers to the constructor which lets you just write Array<int> a; instead of Array<int> a(...);, but I can't see where in the code such a situation occurs...

View 2 Replies View Related

C/C++ :: Custom Binary File Format

Jul 9, 2014

Development of a custom binary file type? So far all I know is the just the basic structures of the binary file type, I know that structures are involved but the implementation part I have run into walls.

View 1 Replies View Related

C++ :: Arithmetic Operators For Custom Class?

Oct 3, 2014

I have made a custom class matrices class which allows me to add, multiply, subtract (etc.) matrices. I have the following method for multiplication but I get an error that says

'invalid use of 'this' outside of a non-static member function'

How can I refer to the current instance without getting this error.

void operator *(Matrices& matrix2) {
this.multiplyMatrix(matrix2);
}

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved