linked-list

In this method I keep getting a return value of One even after I add more nodes

夙愿已清 提交于 2019-12-25 05:38:30
问题 Got a quick question, this is part of a linked list. It determines what the size of the list is, it doesnt work very well at the moment because it keeps returning a 1 even after I add more nodes. public int size(){ ListNode currentNode = null; ListNode previousNode = null; int numberOfNodes = 0; if (head == null) return 0; previousNode = head; currentNode = head.next; numberOfNodes++; while (currentNode != null){ previousNode = currentNode; currentNode = currentNode.next; numberOfNodes++; }

Program Crashing while trying to open a .txt file

风流意气都作罢 提交于 2019-12-25 05:26:14
问题 When I try to run my program it crashes right of the start. The problem is my input from file, I can write to the file fine. Can someone explain why this code wouldn't work?? StringList::StringList() { pTop=NULL; pBottom=NULL; ifstream in; in.open("read.txt"); StringListNode * pCurrent; pCurrent = new StringListNode; pCurrent = pTop; while(!in.eof()) //reads it till the end of file { in >> pCurrent->data; pCurrent = pCurrent->pNext; } in.close(); } This Output to the file works fine. I

Confusion in reversing a linked list through recursion? [duplicate]

余生长醉 提交于 2019-12-25 05:21:10
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Linked list recursive reverse I searched my question on SO and got a link recursion stack trace I din't understand How the head_ref is Pointing to 4 there? Could anyone help me to understand this? 回答1: ok, first of all, it's 6 am here, and i couldn't sleep all night ... so this might be bullshit ;) ... but here we go: the "magic" happens at recursiveReverse(&rest); ... the & says that the parameter is the

read txt file into a sorted linked list c++

十年热恋 提交于 2019-12-25 04:54:08
问题 just started to learn about linked list and have to make a OOP to read, sort, and display some file. Here's the format of the txt file: 20 john adam george . . . the first number is the number of names included in the txt file and each line follows has a name. Here's my main.cpp #include "ListClass.h" #include <iostream> #include <fstream> #include <string> using namespace std; int main() { //declaring class ListClass name; string file; char holder[256]; cout<<"Please enter the data file to

C++ - Linked List code - LNode was not declared in this scope

若如初见. 提交于 2019-12-25 04:37:11
问题 I am writing a class for a linked list in C++ and I am having an issue when writing the operator overload for <<. My class' header is: class LList { private: struct LNode { LNode (); int data; LNode * next; }; public: LList (); LList (const LList & other); ~LList (); LList & operator = (const LList & other); bool operator == (const LList & other); int Size () const; friend ostream & operator << (ostream & outs, const LList & L); bool InsertFirst (const int & value); bool InsertLast (const int

implementation of linked list inside hash table

会有一股神秘感。 提交于 2019-12-25 04:22:38
问题 i am learning data structures and so far have seen linked list,binary tress, and hash tables. I am trying to find a general way to approach a practice problem in which it gives me freedom to use these data structures to solve it. I was hoping to receive some feedback on the best way to solve this problem. The problem tells me to read two files, one file with all the classes and pre-requisites needed to complete a degree and another file that has all classes that have been completed and figure

Linked List Head Is Always Null [closed]

余生长醉 提交于 2019-12-25 04:19:08
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . I have a lab assignment where we have to create a linked list. I have written methods to achieve this. I want to be able to print out my linked list when

Inserting Node into first place C programming

放肆的年华 提交于 2019-12-25 02:45:03
问题 Here is a function of a program I'm writing to get more familiar with nodes. I'm not sure if it is correct but essentially it check to see if the Node is Null if it is then it add the information to the code field and sets the pointer to NULL. Otherwise it creates a new node and inserts the information into the code field and then points to the existing first node. I'm not sure how to change the header that's pointing to the original first node to point to the new node. The code is typedef

wchar_t reading [closed]

怎甘沉沦 提交于 2019-12-25 02:43:12
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I have a mistake in the function for reading the file but I don't know what is wrong. all the symbols are read correctly when the symbol is beyond the ASCII table. while ((c = fgetwc(file)) != WEOF) { if (c != L'\n') { if (i == buf_length) { buf_length += BUF; wchar_t *rebuf = realloc(tmp, buf_length * sizeof

Linked List not working for insertion

 ̄綄美尐妖づ 提交于 2019-12-25 02:34:18
问题 I have written a linked list code to insert a element in the node. But the problem is when i want to insert first element using function, the output is coming empty. But when i insert first element inside the main function (see comment line), it gives the correct output. How to solve it ? Here is my C code: #include<stdio.h> #include<stdlib.h> typedef struct node{ int val; struct node *next; }node; void print(node *head){ if(tem == NULL){ printf("List is Empty\n"); return; } node *tem= head;