linked-list

Linked List private pointers C++ [closed]

倾然丶 夕夏残阳落幕 提交于 2019-12-13 10:40:05
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago . I am having trouble understanding how to use pointers when they are in "private". mostly I don't know how to get and set values for pointers I want to create a head and tail node that have no character value. then create new nodes that lie in between head and tail and add new nodes on to the end of

Implementing mergesort on a linked list

南楼画角 提交于 2019-12-13 10:33:06
问题 I was tasked with implementing a merge sort algorithm on a list written in C/C++. I have the general idea down, wrote my code and have successfully compiled it. However, when I run it, it will begin fine but then hang on "prepared list, now starting sort" without giving any kind of error. I have tried to look through my code but I am at a complete loss as to what the issue could be. I am also pretty amateurish with debugging, so using gdb to the best of my abilities has lead me no where. Any

linked list usage to obtain data from file

久未见 提交于 2019-12-13 10:18:21
问题 i have a text file with emails addresses present. i want to obtain those emails and store it in any data structure or variable. Then i need to select mail address from random from the data structure. #include<stdio.h> #include<conio.h> #include <stdlib.h> #include<string> struct link_list { char mail[50]; int counter; struct link_list *next; }; typedef struct link_list node; void main() { FILE *fp ; char string1[80]; node *head; int count_length=0; char *fname = "email.txt"; fp = fopen (

Is it possible to implement an algorithm to find the nth to last element of a singly linked list using recursion in java

♀尐吖头ヾ 提交于 2019-12-13 09:50:07
问题 I know that you can simply solve this question iteratively by using a counter to increment each time you pass a node in linkedlist; also creating an arraylist and setting the data found with each node inside it. Once you hit the tail of the linkedlist, just minus the Nth term from the total number of elements in the arraylist and you will be able to return the answer. However how would someone perform this using recursion? Is it possible and if so please show the code to show your genius :).

How to check whether a linked list is sorted or not using c++?

限于喜欢 提交于 2019-12-13 09:45:00
问题 How to check whether an array or a linked list is sorted or not given a set of numbers using c++?. Is there a function available to check that? 回答1: Simply use std::is_sorted something like: if (std::is_sorted(std::begin(linked_list), std::end(linked_list)) { //... } 回答2: Check this stack overflow link hope you get it your answer. How do I code a function to test if a linked list is sorted 来源: https://stackoverflow.com/questions/35867423/how-to-check-whether-a-linked-list-is-sorted-or-not

Doubly Linked List c++ implementing with a Class

﹥>﹥吖頭↗ 提交于 2019-12-13 09:26:36
问题 I am trying to create a doubly linked list: class DblLinkedBag { private: struct node{ string data; node* next; node* prev; }*start=NULL; int itemCount; string item; node *head; node *tail; public: DblLinkedBag(); ~DblLinkedBag(); int getCurrentSize(); bool isEmpty(); string add(string value); bool remove(string item); void clear(); bool contains(string target); int getFrequencyOf(); string toVector(); string getItem(); void display(); }; So far, I have gotten add, isEmpty, getCurrentSize and

Deep copying linked list

断了今生、忘了曾经 提交于 2019-12-13 09:13:06
问题 I'm trying to implement a stack on the heap using a linked list. However, for using the 'list' function I need to create a deep copy of the linked list, which i'm not completely sure how it's done. Here's a part of my code: class Stack { private: struct Node { int data; Node *next; }; Node *stackTop; public: Stack() {stackTop = nullptr;} Stack(const Stack& original); ~Stack(); bool isEmpty() const; int top() const; int pop(); void push(int newItem); }; Stack::~Stack() { delete stackTop; }

How do linked list work?

偶尔善良 提交于 2019-12-13 09:03:02
问题 I am reading a tutorial and I looked all over google as well but I can't find a good explaantion of details on how a linked list works...I am really confused about the structure/Format and I really wish linked list made sense to me as they sound great, being an array thats resizeable and modifiable...Below is some code I have from a tut if you need to see what I am talking about. I am confused about the methods such as append method or delete, what they do and how tail head thingy in list

Segmentation fault (core dumped) in C byte reader

前提是你 提交于 2019-12-13 09:01:23
问题 I have an assignment for my intro to system operations class that has two distinct parts, the first being a simple program to read an executable, byte by byte, and output the strings entered that are at least 4 characters long. It is a simple modeling of the strings program (command) you can use in UNIX. I'm having a segmentation fault (core dumped) error for three separate sample executables that I feed into it. I understand that this essentially means I'm trying to access some memory

Linked List pushback member function implementation

强颜欢笑 提交于 2019-12-13 08:57:58
问题 I am a novice programmer and this is my second question on Stack Overflow. I am trying to implement a pushback function for my Linked List by using a tail pointer. It seems straightforward enough, but I have a nagging feeling that I am forgetting something or that my logic is screwy. Linked Lists are hard! Here is my code: template <typename T> void LinkedList<T>::push_back(const T n) { Node *newNode; // Points to a newly allocated node // A new node is created and the value that was passed