C++ :: Insert Into Certain Position In Double Linked List?
Jul 26, 2013
I'm having trouble inserting a node in a nth position into a double linked list. My for loop is giving me an exception handler error and I can't link the node after the new node is inserted back to the new node. Here is my code,
void mylist::insertpos(const int &pos, const string &s, const int & c) {
listnode* temp1 = new listnode(s,c);
temp1->s =s;
temp1->next = NULL;
[Code]....
I attached my header file incase you need to see the definitions for my objects.
View 4 Replies
ADVERTISEMENT
Mar 4, 2014
I have been working on a program that records the time it takes the user to complete a maze. The user's time is then recorded and inserted into a linked list of structures based on the time (from quickest time to longest). I wrote some code that does this, but I was wondering if I can make the code more concise/make sense -- like only using two pointers or having less if statements.Here is a struct that are the elements of the linked list (I also have a global variable to keep track of the head of the list:
Code:
//stores player's best time.
struct PlayerTime {
char name[MAX_STR_LEN];
float seconds;
struct PlayerTime* next;
[Code]....
View 4 Replies
View Related
Sep 30, 2014
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
struct ddpl{
string author, title, show_title, choice, user_name, borrowed_book_title, borrowed_book_author;
[Code] ....
I don't know how to do this if this was deleting by position would have been easier, but the user don't know and don't have to know the position of every book in the list it should delete the books by there title and i'm kinda lost of the delete function at line 47 and particularly at line 55 and 62, it kind difficult to traverse with the values or the data of the node for the position is simpler.
View 14 Replies
View Related
Oct 25, 2013
I have a problem with inserting a node between two nodes.
Code:
#include <stdio.h>
#include <stdlib.h>
struct listelem {
int nbr;
struct listelem *next;
[Code] ....
View 8 Replies
View Related
Feb 17, 2013
I'm trying to make a function that lets me pass an index and a string and will insert the string at that index in the linkedlist... here is so function i have so far:
Code:
typedef struct node {
char* value;
struct node* next;
} LinkedList;
void llAddAtIndex(LinkedList** ll, char* value, int index) {
[Code] .....
View 4 Replies
View Related
Feb 12, 2014
I have a program and function i'm having an issue understanding. Here is what it's doing in the main.
int main() {
orderedLinkedList<MemberDO> memberList;
MemberDO::readFromFile("Member.dat", memberList);
return 0;
}
So it is creating a linked list object using the MemberDO class type which has a int, string, char and double. Then it will call the readFromFile static function in the MemberDO. So this is where my problem is I have this function
void MemberDO::readFromFile(char *fname, orderedLinkedList<MemberDO>& list) {
}
How do I read in each individual data member from the input then create a new MemberDO object and insert the objects into the linked list specified in the second argument list?
Here is the MemberDO class declarations
class MemberDO {
private:
int key;
string lastName;
char firstInitial;
double dues;
[Code] ....
View 4 Replies
View Related
Oct 14, 2014
It is suppose to insert items in Linked List in sorted ascending order and no duplicates are allowed.The code complies but it creates duplicates out of order.
ListRetVal CSortedList :: InsertItem(const ListItemType &newItem)
{
ListItemNode* newLNode = new ListItemNode();
newLNode->value=newItem;
newLNode->next=NULL;
[Code].....
View 5 Replies
View Related
Feb 17, 2013
I'm still trying to insert a node at a passed index in a linked list. This is my function, it doesn't work but i feel like it's close.
Code:
void llAddAtIndex(LinkedList** ll, char* value, int index) {
LinkedList* newNode = (LinkedList*)malloc(sizeof(LinkedList));
newNode->value = value;
LinkedList* prevNode = *ll;
for(int i = 0; i < index; i++){
[Code] ....
View 2 Replies
View Related
Feb 8, 2014
How to randomly insert certain numbers into a linked list with 10 nodes. Meaning I want to put for example numbers 1 5 10 15 20 25 30 35 40 50 in random locations in the linked list.
View 1 Replies
View Related
Mar 16, 2014
is this correct? I used this sorting with numbers i don't know if it is the same with strings. When I run it, there are no errors detected, but when i try to view it, the inputs does not appear.
void add(node **h, node **t){
node *temp, *ptr;
char s[20];
temp = (node*) malloc(sizeof(node));
printf ("-INSERT-");
printf("Fruit: ");
scanf("%s", temp->fruit);
[Code] .....
View 1 Replies
View Related
Feb 20, 2014
I'm trying to figure out how to insert a node into a linked list at a particular location based on a time..I have this declared outside of everything globally.
Code:
struct aTime {
char name[LENGTH];
int time;
struct aTime* next;
};
struct aTime* head = NULL; And then this function that is used to add nodes (aTime structs) to a linked list. It adds the first node fine, but not subsequent ones. I think this is because I have while p-> != NULL but it is always going to be null when the function is called since I create a new aTime struct. So I guess my question is how, after one struct has been added at the beginning, do I point to the head node and traverse the list, insert a node, and make sure everything is still linked? Do I need another temp aTime struct?
Code:
void add_time(char name[LENGTH], int seconds)
{
struct aTime *p;
p = (struct aTime *) malloc(sizeof(struct aTime));
if (head == NULL)
{
strcpy(p->name, name);
p->seconds = seconds;
}
[code]....
View 3 Replies
View Related
May 16, 2013
Error:
--------------------Configuration: nc - Win32 Debug--------------------
Compiling...
cv.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/nc.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
nc.exe - 2 error(s), 0 warning(s)
Compiles with 0 error but on running 2 Errors appear.
I'm Inputting data of an object from user and then inserting it in the link list.
#include <iostream>
//#include <fstream>
using namespace std;
#define LEN 100
////////////////////////////////////////////////////////////////////////////////////////////////////
class employee{
[Code] ....
View 1 Replies
View Related
Jan 2, 2014
I'm having a small issue here with my linked list.I built a linked list with strings and it worked perfectly.Now since i'm using strtok() to separate the string.for now here's what i've got:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct dict_word *word;
typedef struct node *Node;
typedef struct double_linked_list *DLL;
}
[code]....
View 1 Replies
View Related
Jun 29, 2013
I have a linked list comprised of chars like so...
Code:
node1 - "p"
node2 - "o"
node3 - "p"
I need a function that will take in three perameters...node *replaceChar(node *head, char key, char *str)Stipulations of this function. head is the head of the list, 'key' and 'str' are guaranteed to contain alphanumeric characters only (A-Z, a-z, and 0-9). str can range from 1 to 1023 characters (inclusively). So if I call this function with these perameters..
Code:
node *head == /*the head of the list to be examined*/
char key == "p"char *str == "dog"The new list will look like this...
node1 - 'd'
node2 - 'o'
node3 - 'g'
node4 - 'o'
node5 - 'd'
node6 - 'o'
node7 - 'g'
All instances of 'p' were replaced with 'dog' I have a toString function which takes in a string and converts it to a linked list and returns the head. So assume that you can call the function on str = "dog" so...
Code:
toString(str) == /*this will return the head to the list made from the str*/
If it's unclear what my question is...I am stumped on how to write the replaceChar function the one that takes in three perameters..
View 3 Replies
View Related
Dec 27, 2013
I'm trying to set up a simple implementation of a double linked list... But I seem to some mistakes.
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
#define ValueType int
struct vertex {
[Code] ....
I get 'Test: root exists' printed out, but not the loop through my linked list.
View 11 Replies
View Related
May 12, 2014
So im trying to write a code that will take data in from a user and when that user enters specific character then i want to pop the top of the stack and place that node on a new stack. Then if the user enters a different specific character then i want to place what was just popped off the stack back on to the original stack. Anyways i'm just testing what i have without all the complicated stuff with the specific characters, but i get an error and i'm not not well versed in exception handling. So this is what i have so far. the push seems to work well but the pop seems to be giving me problems.
Stack::Stack(){
top = NULL;
bottom = NULL;
}
//method to push a line of text onto the stack
void Stack::push(string data)
[Code] .....
View 4 Replies
View Related
Apr 2, 2013
I am developing a double linked list in C ( development environment ) is QT with mingw32 4.7 gcc / g++ compiler , in the header file I have defined struct as follows :
Code:
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <stdlib.h>
#include <sys/stat.h>
#include <signal.h>
#ifndef NULL
[Code] ....
When compiling I am getting the following error : 'NODE' undeclared (first use in this function)
and
each undeclared identifier is reported only once for each function it appears in
I have also attached the screen shot from the QT IDE
look's like the compiler is not able to pick up the definition of NODE structure , same happens in Netbeans IDE , interesting thing is if change the source file from c to cpp the error goes away .
View 3 Replies
View Related
Aug 22, 2014
I am trying this without a head/start pointer which would generally hold the address of first node. I have 3 nodes here from which I am trying to delete last node, but its not happening. I might be wrong in my logic and this is my first linked list program.
#include <stdio.h>
#include <stdlib.h>
struct dll{
struct dll *prev;
int data;
struct dll *next;
[Code] ....
output::::
add of p1::0x9605008 add of p2::0x9605018 add of p3::0x9605028 add of p1->prev::(nil) add of p1->next::0x9605018 add of p2->prev::0x9605008 add of p2->next::0x9605028 add of p3->prev::0x9605018 add of p3->next::(nil)
no of nodes 3
enter the addresss of node to delete it
0x9605028
after deletion attempted
add of p1::0x9605028 add of p2::0x9605018 add of p3::0x9605028 add of p1->prev::0x9605018 add of p1->next::(nil) add of p2->prev::0x9605008 add of p2->next::0x9605028 add of p3->prev::0x9605018 add of p3->next::(nil)
no of nodes 3
In this example i am trying to delete the node 3 which is p3, by deleting its address 0x9605028. But after deletion the node count is still 3 and addresses are like unexpected!
View 1 Replies
View Related
Mar 25, 2014
I am doing c++ program to read coordinates from text file into double linked list. Everything seems to work perfectly but it stores only 298 items in linked list. Im not sure if my code is wrong or I missed something. On the debugger length of list is over a 1000 but like I said it print outs only 298.
View 2 Replies
View Related
Apr 28, 2015
I have to write a c program that will allow the user to enter names with ages. The name will be no longer than 40 characters. The name and age should be stored in a node of a doubly linked list. I cant use global data. I need to use 3 subroutines. the first one needs to enter the data and pass the head and tail pointers to the subroutine. the next subroutine needs to print the names and ages to the screen and file output.txt from first to last. the last subroutine needs to print out names and ages to the screen and file output.txt from the last to first.
Im getting several errors when i try to run this program. The first subroutine to get the data from the user and build the double linked list. but i seem to be having issues.
#include <stdio.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int entry(char [][41], int []); // subroutine used for data entry //
void printit(char [][41], int [], int); // subroutine used for data printing //
void reverseprintit(char [][41], int [], int); // subroutine used for reverse data printing //
[Code] .....
View 11 Replies
View Related
Jun 27, 2014
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?
View 2 Replies
View Related
Jun 15, 2013
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
View 6 Replies
View Related
Feb 4, 2015
I have a mfc project with a List Control (Report View).
When I run the project, the list control appears in the middle of the window instead of appearing where I placed it.
Is there a qay to make it stay where I need it?
View 2 Replies
View Related
Aug 16, 2013
im trying to code a simple list box for my self made GUI but i seem to be stuck at the scroll bar. I already finished with the calculation for the scroll bar size but how I could calculate it's current vertical position depending on the current item on top of the list box.
My current code looks like this
ListBox struct:
struct MenuListBox {
int PosX;
int PosY;
int Width;
int ItemsVisible; //Items visible at the same time
int CurrentItem;
[code]....
Additional vars in the menu class:
MenuListBox* MenuListBoxes;
int ListBoxCount;
How could i calculate this:
New->CurrentScrollBarPosY = ; ?
View 15 Replies
View Related
Jun 2, 2014
I am on a little project involving TCP socket-programming and multiple threads but need passing structures between two threads.
The first thread receives data with respective ID, temp, etc,.. Each ID is a list-item of a linked list and every ID has again a linked list of all the received data.
The second thread just have to access the list and perform some manipulations on it.
My solution: pass the head pointer of the linked list. Easy enough, right? Somehow, I am stuck receiving error message:" dereferencing pointer to incomplete type."
For the sake of ease and simplicity I just added a stripped down version of the project.
The magic (or not) happens in MainProcess.c: The Data thread should receive the pointer (a think) from the Connection thread.
View 5 Replies
View Related
Apr 29, 2013
I'm trying to write a function that takes two linked lists and creates a third one with only the common elements.
It assumes the first list (the caller) has no dups, but it doesn't seem to be working. The program doesn't crash, it just hangs when it is supposed to display L3 (the third list)..everything else runs and is displayed fine.
template <typename T>
LList <T> LList <T>:: common (LList <T> &B)//common fct
{
Node <T> *hunter1 = Head;
[Code]......
View 10 Replies
View Related