C++ :: Implementation Of Circular Queue Of Array Containing Names

Jun 28, 2013

/* Implementation of a circular queue of Array containg names.. */
# include <stdio.h>
# include <conio.h>
# include <stdlib.h>
# include <string.h>
# define QSIZE 5
typedef struct{

[Code] ....

I changed my code. but whenever i typed in the ILoveBacolod it takes it as a whole, and if i deleted it deletes the string not the letter. for example:

Enter String: ILoveBacolod
Enter a command: Delete (D)
Output: LoveBacolod
Enter a command: Delete (D)
Output: oveBacolod
Enter a command: Add (A)
Enter a character: z
Output: oveBacolodz

View 2 Replies


ADVERTISEMENT

C/C++ :: Error In Circular Vector Implementation Of Sorted Priority Queue

Mar 1, 2015

There appears to be some kind of error in by removeMin() function. Inserting items seems to work just fine but attempting to remove any items gives me the error "vector subscript out of range".

Here is my SortedPQ class... Below it you will find the quicksort implementation, in case looking at it is necessary.

template <class Type>
class SortedPQ {
private:
int front;
int rear;
vector<Type> V;
public:
SortedPQ(void) : front(-1), rear(-1), V(0){}

[Code] ....

View 1 Replies View Related

C :: Circular Queue Based On Struct

Oct 6, 2013

I am stuck with how to make a circular queue that are based on a struct. Have been reading about the implementation but cant really understand it fully. Here is what i got so far.

Code:
#define SIZE 10
typedef struct {
char reg;
char brand;
int modelyear;
int mileage;

[Code] .....

View 8 Replies View Related

C :: Access A FIFO (Circular Queue) Between Two Cores

Oct 31, 2014

I want to write a program where one core (core 0) will fill the FIFO and other core (core 1 ) will delete the data from FIFO.

Core 0:

I create a fifo

Code:
struct node
{
int info;
struct node *ptr;
}*front,*rear,*temp,*front1;

And my en-queue function is in core 0 and writing to specific memory location..(which works perfectly)

Code:
void enq(int data)
{
if (rear == NULL)
{
rear = (struct node *)malloc(1*sizeof(struct node));
rear->ptr = NULL;
rear->info = data;
front = rear;

[Code] ....

Now the problem is in the core 1. Here I am unable to read the values from the specific memory location. I am getting garbage value. Where I am doing some stupid error.. I did not understand

Code:
(front->ptr) = (unsigned int *) memory_location;

When I print the (front->ptr) it shows correct memory address but inside the De-queue function in core 1, I am getting wrong value..

Code:
int deq(int buf[n]) {
front1 = front;
printf("Val %d ", front->info); // showing wrong value
if (front1 == NULL) {
printf("

Error: Trying to display elements from empty queue");
return 0;

[Code] ...

View 8 Replies View Related

C :: Circular Queue Using DLL With Globally Declared Pointers Not Being Properly Initialize

Jan 29, 2014

I have a circular queue using DLL which is using globally declared pointers. The problem now is that it is not being initialize properly or being cleared thus my code is not working as expected.

In my code you will be asked how many nodes do you wish to enter "i made 2 default for now", after that you may then add or delete the node. add only works now since delete is still on progress.

When you add the nodes "2 nodes by default" the program will only record the latest input so if i were to input 1 and 2, only 2 will be displayed. I know that this maybe because of my *first and *last variables not being initialize properly.

How should i really work with global pointers? Also im really new to project file programming and not a fan of pointers or linked list at all.

main.c
Code:
void main(){
int ch, number, numdum = 0;
n *new, *ptr, *prev, *first, *last;
first = NULL;
last = NULL;
clrscr();
printf("Enter number of nodes: ");
scanf("%d", &number);

[Code] .....

View 5 Replies View Related

C :: Display The Names In A Queue

Mar 12, 2014

I have an assignment that needs to display the names of customers to be served according to a sequence. coding to display the names accordingly?

Code:

#include <stdio.h>
#include <stdlib.h>
#define MAXIMUM 20
void create();

[Code].....

This is my output. I have trouble displaying the names of the customers as it outputs null when I try to display my position in queue.

View 4 Replies View Related

C/C++ :: Display Names In A Queue?

Mar 13, 2014

I have encountered errors when trying to display the customers' names in a priority queue.

#include <stdio.h>
#include <stdlib.h>
#define MAXIMUM 20
void create();
void priority_insert(int data);
void check(int data);

[code]....

I have gotten the following output:

Peter
Peter
<Null>

How do I correct my coding to display like below:

John
Peter

View 1 Replies View Related

C :: Queue Implementation - Linked List

Mar 23, 2013

I am trying to create a code to represent a queue using a linked list but i get the disturbing "Segmentation fault coredumped" after compilation.

Code:

#ifndef QUEUE_H
#define QUEUE_H
#include <stdbool.h>

typedef int Item;
typedef struct queue_type *Queue;
typedef struct node *return_node;

[Code] .....

View 2 Replies View Related

C/C++ :: Implementation Of Stress Test For Lock Free Queue

Aug 31, 2014

I am trying to compare performance of different lock-free queues, therefore, I want to create a stress test - which includes pushing/popping user-defined pre-built objects to and from the queue. My question is how can perform the stress test with pushing and popping objects instead of pointers to object like I have done in my code. What is the different in terms of performance of pushing/popping objects Vs. pushing/popping pointers.

#include <cstdlib>
#include <stdio.h>
#include <string>

[Code]....

View 3 Replies View Related

C++ :: Increase Sizes Of Queue In A Vector Of Queues And Find Shortest Queue

Feb 20, 2013

I have a paradigm in a loop of queues of a vector,if a condition is true,increase sizes of the queue of that particular queue in the loop of queues, if condition is false, the queuesize is left as such in loop of queues. After this operation i need to search the queue sizes of all queues and enqueue in the shortest queue.

I want to do something like the code given below

#include <vector>
#include <queue>
int min_index = 0;
std::vector<std::queue<int> > q
std::size_t size = q.size();

[Code] ....

How to implement this logic?

will q[i].size=q[i].size+5 increase the queuesize by 5 for the ith queue?

View 12 Replies View Related

C++ :: Delete Specified Names From A List Of Store Names?

Feb 10, 2013

i have a vector of stores. i would like to delete the specified choice(store) from the list. Here is what i have but my erase statement is wrong and wont compile.

void Store::deleteSpecifiedStoreFromList(string choice) {
for (int i = 0; i < this->stores.size(); i++) {
if(this->stores[i].getStoreNames() == choice) {
this->stores.erase( std::remove_if( this->stores.begin(), this->stores.end(), choice ), this->stores.end() );
}
}
}

View 4 Replies View Related

C++ :: Priority Queue - Inserting Into Bottom Of Array

Jan 24, 2013

i am working on creating a priority queue, i seem to have done the algorithm for inserting from the top correctly but the algorithm for inserting from the bottom doesnt seem to work it just overwrites the existing data.

below is my code :

list is an array and listlength is the size of the array declared as a integer

void inserttop(string task) {
//int head = 0 ;
string temp ;
listlength++ ;
for (int i = 1; i < listlength; i++) {

[Code]...

View 2 Replies View Related

C++ :: Heap And Priority Queue (Array Not Storing Digit)

Feb 27, 2015

This assignment is about Heap and PQ's to sort out jobs inside a printer. I'm far from finishing the assignment but the most important part isn't working. My issue is that nothing is getting stored inside the array. I keep getting crashes and at this point I'm not sure what to do. I notice that my destructor runs right after my "addJob" Function finishes, which is destroying the memory. Which might be why nothing gets stored inside OR I think my implementation of Heap/PQ is wrong.

Functions inside my test.cpp aren't properly done, they are made just to see if something is stored inside.

1. Check if I created the array correctly [PQtype.cpp / Heap.h/ PQType.h]
2. Am I even using/storing into the array. [Test.cpp "addJob" Function]
3. I'm also new to working with Class Templates.

PQType.h
template<class ItemType>
class PQType {
public:
PQType(int);
PQType(const PQType&); /

[Code] .....

View 4 Replies View Related

C :: Array Of File Names

Feb 9, 2013

I am trying to create an array of file names such that when I want to open one of the files, who's name is given in the array, I can call that element of the array. My code for making the array is the following,

Code:
char file_name[40];
char *file_locations[N]; // array of N names (*)
for(ii=0; ii<=N-1; ii++){ // printing the names of all the files P1_8mag_1.txt - P1_8mag_N.txt
sprintf(file_name, "P1_8mag_%i.txt", ii+1);

[Code]....

The problem with this is that in the first step: all elements of the array "file_locations" are the name of the last file in the loop (in this case "P1_8mag_N.txt")What is wrong with this?

View 12 Replies View Related

C++ :: Array Based Implementation Of Linked Lists

Jul 19, 2014

I first want to say that i am trying to solve my code without Pointers.

My goal is to..
1. Construct an empty 2D array with a capacity of 25. (list[25][2];)
2. Empty(): test if the stack is empty
3. Push(): add a value to the stack in the (list[i][0] = value;) position and (list[i][1] = previous list[i][0] position)
4. Top(); read the value(list[i][0]) at the top(count) of the stack
5. Pop(); remove the value at the top of the stack (list[i]= 0;)
6. Display(); displays all the elements in the stack going from the top to bottom order. (shows array index, data value, and next array index)

I have hit a road block and don't know what to fix or where to go from here.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
char name[5];
srand(time(0));
//Protoypes
void construction(int table[25][2]);

[Code]...

View 1 Replies View Related

C++ :: How To Store Names And Numbers In Array

Jul 25, 2014

Can names and numbers be stored in one array ? Like a telephone directory?

View 1 Replies View Related

C/C++ :: Unable To Use Priority Queue Sorting In Reverse Order To Take Vector Or 2D Array

Aug 7, 2014

I'm trying to use a priority queue sorting in reverse order to take a vector or 2d array. The problem is that I want to sort by the vector/array cell value but keep the reference to the vector/array index of the value. I don't know quite howto keep them both related so when I pop. I can find the corresponding cell.

priority_queue<int, vector<int>, greater<int> > Open;

View 2 Replies View Related

C++ :: Implementation Of Array Index Operator For Fraction Class

Jan 7, 2014

I need an implementation for the array index operator overloading of my Fraction class . The Fraction.h looks like :

#include <iostream>
using namespace std;
class Fraction {
public:
Fraction(int = 1, int = 1);

[Code] .....

I am not able write the Array index operator overloading functions.

View 3 Replies View Related

C++ :: Array Versus Linked List Implementation For Stack

Nov 27, 2014

Basically what are the advantages and disadvantages of having an array implementation vs linked list implementation for a stack?

View 1 Replies View Related

C/C++ :: Array Implementation Of Stack To Reverse Columns In Matrix

Dec 1, 2014

I had the following question in my exam paper and only got 1.5 out of a possible 6 marks. This is the question:

Given the Matrix class:

class Matrix {
public:
Matrix(unsigned r, unsigned c);
Matrix(const Matrix<T>& rhs);
~Matrix();
const Matrix<T>&operator=(const Matrix<T>& rhs);
[Code] ....

Use the linkedStackType class (Array implementation of stack) and write a function reverseCols to reverse the order of columns in the matrix. Note that reverseCols is not a member function of the Matrix class therefore only the public interface of matrix can be used.

//Implementation of Stacks as Array
template<class Type>
class stackType: public stackADT<Type> {
public:
const stackType<Type>& operator=(const stackType<Type>&);

[Code] ....

What is the correct solution must be to reverse the columns of the matrix?

View 1 Replies View Related

C++ :: Reading Names In Array Separated By A Comma

Jul 7, 2013

I'm trying to read names separated by a comma using array.

For example, the expected input would look like the following:

Juila,Francisco
Adams,Wong

I know you can use getline function and set the delimiter to comma. So like ....

getline(cin, lastName, ','); getline(cin, firstName);

But the program only read the last name and ignore the firstname.

View 1 Replies View Related

C :: Seg Fault When Reading File Of Names Into Array

Jun 19, 2014

I am having trouble reading in a file of 10 names into an array. Ive already allocated the memory, I just keep getting a seg fault when I try and read in the names.

Code:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define MAX_STRING_LEN 25

void insert_data(char **strings, const char *filename, int size);
void allocate(char ***strings, int size);

[Code] ....

And then the list that I have to read in is as follows:
matt
susan
mark
david
aden
phil
erik
john
caden
mycah

View 1 Replies View Related

C :: How To Account For Different Number Of Chars In Array Of Names

Dec 9, 2013

I am trying to make a for loop that will print out chars in an array while using a #define before main. My problem is that each name has a different amount of chars in it. How do you account for that when you are trying to define a size? For example, I am playing around with the numbers and I just put 7 in for size:

Code:
#include <stdio.h>
#define sizeOf 7
//char personName( char * name[] );
char printName ( char * name[]);

[Code] .....

View 8 Replies View Related

C :: Arrange Set Of Names In Array In Alphabetical Order

Oct 25, 2013

I am having problem with comparing first letter of every wordso that i can arrange them in array.

Code:
/*22/10/13 15:30
Arrange set of names in an array in alphabetical order
*/
#include<stdio.h>
main( ) {
int x,a,i=0,j;
char *temp, *str[]={

[Code] ....

I am getting unexpected output here :

Code:
himanshu
amit
nitin
saurabh

View 3 Replies View Related

C :: Program To Simulate Taxi Rank Implemented As Queue Via Array - Linked List

Mar 26, 2013

I have an assignment where i am required to code up in C, a program to simulate a taxi rank that is implemented as a queue via an array that can hold up to a maximum of six taxis.When a taxi arrives, it joins the rear of the queue. When a taxi departs, the first taxi in the rank is used and its departure is logged.A "rolling menu" comprising integer codes as specified below is used until 0 is entered to exit the simulation. I've done this stage but now the next stage is asking me to implement the queue as a linked list. what the difference is between an array and a linked list and what is a linked list?

View 2 Replies View Related

C :: Program To Evaluate Postfix Expression Using Array Implementation Of Stack

Apr 26, 2014

Write a program that evaluates postfix expression using array implementation of stack.

The expression [the input] is evaluated from left to right using a stack. When the element read from the expression is an operand, push it into the stack.When the element read from the expression is an operator: Pop two operands from the stack.Evaluate the two operandsPush the result of the evaluation into the stack.

The final result lies on the top of the stack at the end of the calculation. Make sure to display the result before terminating the program.Write a program that evaluates postfix expression using array implementation of stack.

Code:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define M 20

typedef struct{

[Code] ....

View 1 Replies View Related







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