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


ADVERTISEMENT

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++ :: 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 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/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++ ::  Accessing Struct Data In A Queue

Mar 24, 2013

I have a queue of structs. I would like to access one of the two pieces of data at the front of the queue that each struct maintains.

Here is some of my code:

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <queue>
using namespace std;

[Code] ....

What I am asking is how do I get the priority of the struct item at the front (lane1.front()), in this case?

View 8 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/C++ :: Sizeof (struct) Returns 6 More Bytes Than Actual Struct Size?

Sep 14, 2014

#include <stdio.h>
#define MAX_USERS 20
struct {
char ID[10];
char Name[40];
int Pos;

[Code] .....

I was attempting something weired with address to move data around when I discovered that the size of the array is not what I expected. I am passing this structure as &Users to a function that declares it as a void *, then I can deal with chunks of data (memmove) and not have to worry about index or things like that. However...sizeof is returning something I do not understand.

View 9 Replies View Related

C++ :: Circular Right Shift A Cstring

Jan 29, 2013

I need to circular right shift a cstring in C++

Let's say I have unsigned char test[10] = "HELLO!!!"; How would I go about circularly shifting this to the right? Inline assembly instructions would be ok too

View 6 Replies View Related

C++ :: Rotating A Circular Disk?

Aug 30, 2013

Any algorithm or function to rotate a displayed circle. To turn it 360 degrees like a car-tire. (It's needed to turn a turn-table in a model-railrod control program) .....

View 14 Replies View Related

C++ :: Circular Reference Not Working?

Mar 15, 2013

It's compiling but it's not working, it enters in stack overflow. It's a Doubly Linked List I'm compiling in Visual Studio. I think there's nothing wrong with this declaration, but there's just might be it:

class ListItem;
class List {
public:
ListItem *firstItemRef;

[Code] .....

View 7 Replies View Related

C/C++ :: Circular Permutation Through Function

Jan 17, 2015

I need to create such a function that the content of the first is put into the second, the content of the second into the third and the content of the third into the first.

For example, output should be like this
3
2
1
But the code below prints out:
1
2
2
Where am I making a mistake?

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>

[Code]....

View 2 Replies View Related

C# :: Circular Progress Bar In WPF (Not Silverlight)

Jul 30, 2014

Is there a way to make a circular progress bar in WPF without using another library or NuGet Package?

Like a tutorial on how to make it from scratch?

Right now, I'm using the existing ProgressBar UserControl but it looks horrible especially after I change the Foreground color from Green to DarkBlue.

View 6 Replies View Related

C/C++ :: How To Remove Circular Dependency

Jan 23, 2014

I have ran into some sort of Circular dependency between two classes.

Forward declaration doesn't work as I'm allocating the memory for pointer array of Student and it requires the default constructor.

P.S I'm aware I haven't written the BIG 3, it's an incomplete code. Just want to know how to resolve this dependency.

class Student;
class Course {
char *name;
Student *s[3];

[Code].....

View 14 Replies View Related

C++ :: Circular Dependency In Template Arguments

Nov 7, 2013

Today I faced a problem where I had circular dependency in my template arguments. I was trying to make a class hierarchy similar to:

template<class BType>
class A_base {
public:
BType* getB();
};

[Code] .....

Basically I had objects that were of type A<B<A<B<...

Basically I have a tree like structure of heterogeneous types that must facilitate two-way interactions where A's can call B's and B's can call A's. This structure is useful in many contexts the difference is the methods A and B provide are different in each of these contexts. Instead of adding the getA and getB and all the other connectivity methods in every version of A and every version of B, I wanted to create a base class that managed this automatically.

Another piece of advice was break up your code so there is a forward-only and backwards-only dependent types. This is not a complete solution because the two cannot know about the other and this does not really facilitate arbitrary two-way communication (where A calls B then B calls A back). It also makes the code more complicated in that I have two sets of objects and interfaces.

So the solution was to make the template arguments specific to the things I wanted to be flexible. The connectivity interface of A_base and B_base should be constant. Hence that cannot be in the template parameter. It was merely the traits that I wanted to make flexible so... I came up with this solution:

#include <iostream>
template<class aTraitType,class bTraitType>
class A;
template<class aTraitType,class bTraitType>
class B;

[Code] ....

Now this compiles and works great. The problem is that aObj and bObj cannot call their opposite within a trait method because print() does not know anything about the connectivity. So the solution there was to make traits an abstract base class. Then magically everything works!

#include <iostream>
template<class aTraitType,class bTraitType>
class A_base;
template<class aTraitType,class bTraitType>
class B_base;

[Code] .....

So this outputs the following. Clearly there is two-way communication!

Class A is not connected to B
Class B is not connected to A
Class A at 0x7fff25d1aa10 reporting for duty
Class B at 0x7fff25d1aa00 reporting for duty
Class B at 0x7fff25d1aa00 reporting for duty
Class A at 0x7fff25d1aa10 reporting for duty
Class A at 0x7fff25d1aa10 reporting for duty
Class B at 0x7fff25d1aa00 reporting for duty

View 6 Replies View Related

C++ :: Fixing Circular Dependencies With Pointers

Dec 18, 2012

I've been making a project that requires different files to have access to objects declared in other files such that circular dependencies are created. I've done some research and discovered that pointers and forward declarations should be able to fix this.

Example:

File 1 declares variable x, must edit x and y

File 2 must edit x and y, declares variable y

I know this isn't the best example, as you could probably declare x and y in the same file, but please suffice it to say that I'm unable to do that in my project.

View 10 Replies View Related

C++ :: Creating Circular Linked List

Jan 30, 2015

I've been making a circular linked list and I'm trying to assign each list a "name" and its next "link" but when I run my code it crashes.

Soldier *Head;
Head = NULL;
string names[] = {"Arman","Bogut","Castro","Damascus","Elene"};
for (int i = 0; i < 5; ++i) {

[Code] .....

View 4 Replies View Related

C/C++ :: Make Circular List And Print It

Apr 28, 2015

I have this program. I am trying to do this Circular List but i think something going wrong. The first of all is the list.The second is if my code for delete and select function are correct and the third i would like my program getting a "n" number of names and then make the circural list then print it and then when i select a number delete every node until give us the only one left.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 10
#define NUM_PER_LINE 6
typedef struct node {
char name[SIZE];
struct node * next;

[Code] .....

View 1 Replies View Related

C++ :: Circular Doubly Linked List Code

Feb 27, 2014

When I run this in main it gives me a windows error message. I believe it has something to do with my insertAtEnd function but I've gone over it a million times....

#include<iostream>
#include<string>
#include<vector>
#include"RhymeGame.h"
using namespace std;
Game::Game() {
head = NULL;

[Code] ....

View 3 Replies View Related

C++ :: Adding To The End Of A Doubly Linked Circular List?

Dec 2, 2014

Should my if statement be

if (tail== NULL) or if(tail->next == tail) ?

View 4 Replies View Related

C/C++ :: Reversing A Circular Doubly Linked List

Apr 25, 2015

I print the original list, then reverse it, then try to print it again. Here is what I get when I do that:

So that second line should print 2 1 4 5

Here is the reverse function:

void reverseCirListDeque(struct cirListDeque *q)
{
struct DLink *curr = q->Sentinel;
do{

[Code].....

View 2 Replies View Related

C/C++ :: Pointer To Last Node Of A Circular Linked List

Nov 30, 2014

Why is it sufficient to only have a pointer to the last node of the list?

View 3 Replies View Related

Visual C++ :: No Circular References But Undeclared Identifier

Jun 11, 2014

Each of my header includes is protected by directives. I think I don't have to include Boolean in my work space because it is already included in the external dependencies section. and the Boolean.h is in the include path.

MachineShop, Boolean etc got undeclared identifier error

Tried to comment out the directives, to no avail.

Code:
#include <iostream>
#include <string.h>
#ifndef BOOLEAN_H_
# include "Boolean.h"
#endif
#ifndef PROCESS_H_
# include "Process.h"
#endif
#ifndef MACHINESHOP_H_

[Code] ....

View 2 Replies View Related

C/C++ :: Add Function To Tail Of A Doubly Linked Circular List

Nov 30, 2014

I have a function that I would like to add to tail. It is not correct.

template<class T>
void DoublyLinkedCircularList<T> :: addToTail(T element) {
DoublyLinkedNode<T>* head;
DoublyLinkedNode<T>* temp;
temp->element = element;

[Code] .....

How do I fix it?

View 14 Replies View Related

C/C++ :: Circular Buffer In The Form Of Finite State Machine

Dec 11, 2014

I'm supposed to create a circular buffer that reads an input file and outputs data after running though basically an integral equation. Everything my be referenced by pointers. When I build I am being told segmentation fault: 11. From what I have gathered that means there is a problem with my memory allocation correct? I'm including the custom header file and the main.c as well.

header file :

#ifndef FSM_H
#defineFSM_H
#define INPUT_BUFFER_LENGTH 2
#define OUTPUT_BUFFER_LENGTH 2
#define INITIAL_INPUT {0,0}
#define INITIAL_OUTPUT {0,0}

[Code] .....

View 1 Replies View Related

C++ :: Doubly Linked List - Circular Dependency Error

May 15, 2013

When compiling the source I get the following error

"pms_program.h:54:56: error: expected declaration specifiers or ‘...’ before ‘CourseType’"

the code you are looking for in pms_course.h ( there is a circular dependency between pms.h , pms_course.h and pms_program.h)

function prototype AppendProgram ( part of doubly linked list )

I have attached the full course code.

As much as I like I cannot change the structure of the startup code ...

please see attached zip file for the entire source code.

View 6 Replies View Related







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