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?
I am trying to make a text editor in C++ that uses Linked Lists as the main driving force. I need to make a program that can add a line of text at a certain point, delete a certain line of text, print the entire text, and quit and save the text to the original text file inputted from the shell script. My problems are with the cpp file, and the linked list files. My remove function is not what I need it to be I know that. I also know that there are some problems with my cpp file myEditor. My code is below.
#include <sstream> #include "linkylist.h" #include <iostream> #include <fstream> #include <string> #include <cstdlib> using namespace std; int main(int argc, char *argv[]) { //node* head = new node;
I am trying to write a function to return the first element of a link list queue. I am not real sure how to implement this. I have include a copy of the struct for my Node & queue.
A while ago i was asked to write a program for a class that used a "Double ended queue with a current-position marker."
An example of some of the functions that i created are:
boolean atFirst() // Returns true if first element is current. Pre: !isEmpty(). boolean atLast() // Returns true if last element is current. Pre: !isEmpty(). void makeEmpty() // Sets this List to the empty state. Post: isEmpty(). void moveFirst() // Sets current marker to first element. void movePrev() // Moves current marker one step toward first element. void moveNext() // Moves current marker one step toward last element. void insertBeforeFirst(int data) // Inserts new element before first element.
My question is whether a double ended queue with pointer is the same thing as a "doubly linked list" in this case. The terminology is throwing me of a little. If the two concepts are different, how is a doubly linked list different?
Well, basically, what I've been doing was creating a class that would implement the concept of Double Linked List, but that would behave like a queue ( the STL implementation is deque, or Double Ended Queue ).
The problem occured when I have been trying to generalize the class using templates. I mean, why use only integers ? Why not double or char or what not ?
Worked perfectly before including all the template stuff..
// Source.cpp <=> Main.cpp #include <iostream> #include "DList.h" using namespace std; int main(void) { DList<int> *list; list = new DList<int>();
[Code] .....
The errors returned by the compiler:
Error1error C2955: 'Node' : use of class template requires template argument listc:usersjumperdesktopc++ otherdouble linked listdouble linked listdlist.h6 Error2error C2955: 'Node' : use of class template requires template argument listc:usersjumperdesktopc++ otherdouble linked listdouble linked listdlist.h6
Consider a program that simulates a card game, with multiple player hands and a deck to draw from. Each hand can use an array to represent the cards it contains; sometimes it is useful to also declare an additional variable for each hand (or deck) indicating exactly how many cards are present.
1) Describe a simple function that would manipulate both the array representing a hand and the number indicating the size of the hand.
2) Describe a simple function that might be able to manipulate the array without referring to the hand size variable at all.
3) Generally, if the array was passed as a parameter to a function, how often would the hand size be included as a parameter?
I'm writing a linked list program for class that has a simple text based menu and I believe I am nearly done, it just wont recognize my "count" function as a function and I don't know why. The error comes up at line 70.
I'm trying to write a program that manipulates a doubly linked list. My professor wants it to have two structs, one called Node (containing the data, and pointers to the next and previous nodes) and one called DLList, which contains the nodes for the head and tail (which is then passed to all of my functions).
I'm a little confused how to access the head and tail, for instance, if I want to initially set them to null in the main function (he emphasized the need for this), or to use them in my functions. I've tried a lot of variations to call the head and tail, but I keep getting told that head and tail are undeclared in the function.
How might I access my head and tail, for instance in a main function, when they're defined like this? (I took out all of the logic in my functions for clarity)
I was trying to implement sorting in a linked list. However, when i run the sortList() function the program abruptly terminates. Here's the complete code:
Code: /* * { * SingleLinkedList.c * * Created on: 28-Nov-2014
I am trying to create an dynamic array (lno) This array will store addressess of different Linked list. What exactly I want is:- Take N Number of Linked List user want to create> eg. 2 now It will create 2 linked list for which I am trying to allocate memory.
Code:
struct node{ int data; struct node *next; }
first; lno[0] Node 0's first address stored in ln[0] lno[1] Node 1's first address stored in ln[1] Here is the code in which I am facing problem with error Illegal structure Operation
I have a 2D array, array[20][3]. Each row represents a storm and each column represents month #, wind speed, and pressure in that order. This data is read from a file and auto-fills the array. I need to be able to give users the ability to add an additional storm or delete a storm. I know that a linked list would be the best approach but I'm not very familiar with linked lists.
I have an algorithm and I want to make it as efficient as possible. Basically it just involves putting numbers in order. I have two options, but which one would be more efficient:
1. Using a doubly linked list. Every time a user wants to add a new number, the algorithm will start searching the correct place for the number from the beginning of the list. This is efficient per se, but once there are about a million numbers and a number has to be put in at the end of the list, the algorithm must go through all the 999 999 numbers before it.
2. Using a container to store all the numbers first, then sorting the numbers. In this case, adding all the numbers is fast, but the actual sorting will take a long time.
Which option would be more efficient? I was thinking of using maybe merge sort or quick sort in option 2. Yes, I'm aware I could just use vector and sort, but that's not my goal here.
I have two arrays of characters that I want to combine and sort according to an internal variable (init) using a forward-iterating linked list. The two arrays must stay separated, as one of the arrays (the enemies) is contained within the object (encounter), the other is passed in via pointers (the players). The array inside the object will be destroyed later (when the encounter is over and the enemies are hopefully dead) while the one that is passed in must survive to be passed into other objects at a later time (the next encounter). My thought is to sort each array by linked list separately first, then iterate through and combine the two lists, But how to do this and no support IRL.
// DECLARATION OF CLASSES // class character{ public: character(); // Constructor
I am having problems implementing ArrayList using templates. I was given a program and I have to create this implementation to make it work. It keeps giving me an error "invalid operands to binary expression" .....
ifndef Final_4_ArrayList_hpp #define Final_4_ArrayList_hpp #define MAX 10; #include "List.hpp" template <class T> class ArrayList : public List <T> {
HelI have been tasked with creating a program which (1) takes in integer values from a user (until the user enters -1) and inputs these values into a linked list. This (2)original list is then to be printed out. The program then uses the algorithm "bubble sort" to (3)order the list in descending order before finally printing it out again.
I have managed to do this but I kind of cheated since I do not quite understand how to manipulate a linked list. What did was I took the values in the linked list and transferred them into an array and then did bubble sort on that array.how to do bubble sort on a linked list as well as how to print a linked list.
Code:
#include<stdio.h>#include<stdlib.h> typedef struct node { int info; struct node *link;
My program seems to be working fine, except for when I call on my delete function. I don't receive any errors, but when I call the delete function my program outputs nothing and freezes. As in, my print function (which is called before the delete function) doesn't even work. I've tried removing bits of the function to see if I could pinpoint where exactly the issue is, but I've had no luck.
#include <iostream> #include <string> using namespace std; class List{ private: struct node{ string _data;
[Code] ....
And the function that is causing me trouble:
void deleteNode(string data){ node* del = NULL; t = h; n = h; while(n != NULL && n->_data != data){
This is in response to the bubble sort and selection sorts for linked lists. On my system, (Intel 2600K, 3.4ghz), it sorts a list with 4,194,304 nodes containing 64 bit unsigned integers in about 1.05 seconds.
Code: #define NUMLISTS 32 /* number of lists */ typedef unsigned long long UI64; typedef struct NODE_{ struct NODE_ * next; UI64 data;