linked-list

Segmentation Fault when using Linux, but not in Xcode

試著忘記壹切 提交于 2019-12-12 04:36:21
问题 I am having issues running my code in a Linux environment. However, it runs perfectly with Xcode. I have used gdb backtrace to pin-point where my problem is and it points to a line of code where I am setting a node's "entry" field (a string) equal to a line read from a text file (also a string). I have a feeling I am not including something or I am including the wrong thing. I am in way over my head since I have just started c++ this month. Please help! #include <iostream> #include <fstream>

Making strcpy function with linked list in c

為{幸葍}努か 提交于 2019-12-12 04:36:19
问题 I was making my own strcpy function using linked list but couldn't get how to do. Without using linked list it could be like this char* cp2014strcpy(char * dest_ptr, const char * src_ptr) { char* strresult = dest_ptr; if((NULL != dest_ptr) && (NULL != src_ptr)) { while (NULL != src_ptr) { *dest_ptr++ = *src_ptr++; } *dest_ptr = NULL; } return strresult; } but I couldn't get how to make strcpy using linked list. 回答1: #include <stdio.h> #include <stdlib.h> typedef struct node { char ch; struct

C calling function on contents of linked list

痴心易碎 提交于 2019-12-12 04:35:55
问题 I am using GLib to manage a linked list. I am declaring 2 structs and the placing them in a linked list as follows. Asteroid asteroid = {0,0,50,50,50} Asteroid asteroids = {0,0,200,200,50}; GList *asteroidList = NULL; asteroidList = g_list_append(asteroidList, &asteroid); asteroidList = g_list_append(asteroidList, &asteroids); Then i use the following function to traverse the list and calla function that draws the struct to the screen as a circle as follows void drawAsteroids(){ GList *list =

Linked list head address changes C

馋奶兔 提交于 2019-12-12 04:33:43
问题 I created linked list of my structure, but for some reason every time I add another link it changes head address, but I want y head address be first entry. this is my code: struct checkPoints *tgh = NULL; struct checkPoints **linkedlist = &tgh; struct checkPoints *cp = malloc(sizeof (struct checkPoints)); chPo = fopen(fileName, mode); if (chPo == NULL) { printf("Can't find the files."); exit(1); } else { for (i = 0; i < lines; i++) { fscanf(chPo, "%c %d %d %d:%d\n", &cp->dropOut, &cp-

First time with linked lists - how do I name objects for insertion

一个人想着一个人 提交于 2019-12-12 04:33:38
问题 Ok, Dumb question time: Usually with an array I have an object name: object[index] ...and if I have many of them then the index is what distinguishes each object from each other, hopefully, and usually in my case the index has a connection of to the reality of whatever the object is representing so I don't have to go hunting - the third one is the third one... Now I have a job that requires a linked list as kind of queue (part of an LRU cache) - I just hit a question: I'm about to declare the

Insert a number to a sorted linked list, why the number inserts to the second position every time?

依然范特西╮ 提交于 2019-12-12 04:24:30
问题 I am working on a project about linked list, I have trouble with inserting a number to a sorted linked list. The number inserted to the second position every time, I cannot figure out where the problem is.Here is my code: void insertSort(struct linkedList *n,int num,int *length){ //insert number to a sort linked list node *new = (node *) malloc(sizeof(node)); //create a new node new->next=NULL; new->data = num; while(n!=NULL&&n->data > new->data){ // find which position num should insert in

Re-ordering a Linked List in Python

放肆的年华 提交于 2019-12-12 04:23:36
问题 I realize this sort of data structure is better done with built in list type, but I'm trying to understand this more for academic reasons. Given that I have a linked list like this: a -> b -> c -> d -> e -> f I would like to change the references to b -> a -> d -> c -> f -> e In other words every pair gets switched. I am using these two classes to create a linked list. class Node: def __init__(self): self.cargo = None self.next = None class LinkedList: def __init__(self): self.cur_node = None

Reverse a linked list without using a pointer to pointer

♀尐吖头ヾ 提交于 2019-12-12 04:15:40
问题 I have successfully implemented the 2 pointers solution using this code: void list_reverse(t_list **begin_list) { t_list *new_root; t_list *root; t_list *next; new_root = 0; root = *(begin_list); while (root) { next = root->next; root->next = new_root; new_root = root; root = next; } *begin_list = new_root; } Which works fine - at least according to my tests. Now I want to try to reverse a linked list using only a single pointer, without return , so I tried to convert my code to void list

C# List<T> adding inherited items [closed]

僤鯓⒐⒋嵵緔 提交于 2019-12-12 04:12:36
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . Let's say that we have 2 classes. The first one is Person using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace People { class Person { public string FirstName { get; set; } public string LastName { get; set;

Adding Numbers to a Range

浪尽此生 提交于 2019-12-12 04:06:07
问题 I'm making a program where I can add an Integer sequence to a Range. I'm having trouble adding this values to the Range. It should run the method addNodeAfter , but it does nothing. Then when I want to display the Range I get a NullPointerException one this line: for (int i = 1; i <= manyNodes; i++){ Any tips? Main: public class PDEMain { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a