linked-list

C++ Template Generics (template argument list)

末鹿安然 提交于 2019-12-13 23:40:26
问题 I am trying to implement a Circular Doubly Linked List, and I have no probably with the Linked List implementation itself. The problem I am having is allowing it to take generic parameters using templates. I have checked several tutorials dealing with templates, but I haven't found anything specific to what I am trying to do. I believe I have worked out most of the errors, but I am still getting the errors: linkedlist.h(37): error C2955: 'Node' : use of class template requires template

Reverse String order of characters and place into LinkedList using a constructor

安稳与你 提交于 2019-12-13 23:26:27
问题 I am making a program that takes a String and puts it in the opposite order into a LinkedList. This code doesn't seem to work (wrong input), and I can't figure out why. Any solutions? public LargeInteger(String input) { TODO size=size+input.length(); LLNode<Integer> curNode=new LLNode<Integer>(); for(int curPos=input.length()-1;curPos>=0;curPos--) { if(curPos==input.length()-1) { head=new LLNode<Integer>(); head.data=input.charAt(curPos)+'0'; curNode=head; } else { curNode.link=new LLNode

Python Linked list minimum value

家住魔仙堡 提交于 2019-12-13 23:08:48
问题 I am trying to find the minimum value in the list without having to use the min function and just by comparing the first and the next element through the list. This is my attempt: def min(self): node = self.head #1st element Min = 0 #node.next_node is the next element while node: if node.value > node.next_node.value: Min = node.next_node.value else: Min = node.value i am just comparing the first and the second element. how do i traverse through the entire list 回答1: Answering this specifically

Quickly make a static linked list

若如初见. 提交于 2019-12-13 22:33:28
问题 I want to quickly make a static linked list, with as little code as possible, which is very readable and without clutter. How do i accomplish this elegantly? something like 1 -> 2 -> 3 -> 4 -> NULL 回答1: struct node {int x; struct node *next;}; #define cons(x,next) (struct node[]){{x,next}} struct node *head = cons(1, cons(2, cons(3, cons(4, NULL)))); 来源: https://stackoverflow.com/questions/29192284/quickly-make-a-static-linked-list

Why does Floyd's cycle finding algorithm fail for certain pointer increment speeds?

谁说我不能喝 提交于 2019-12-13 22:19:03
问题 Consider the following linked list: 1->2->3->4->5->6->7->8->9->4->...->9->4..... The above list has a loop as follows: [4->5->6->7->8->9->4] Drawing the linked list on a whiteboard, I tried manually solving it for different pointer steps, to see how the pointers move around - (slow_pointer_increment, fast_pointer_increment) So, the pointers for different cases are as follows: (1,2), (2,3), (1,3) The first two pairs of increments - (1,2) and (2,3) worked fine, but when I use the pair (1,3),

Assignment Operator for Doubly Linked List in C++

僤鯓⒐⒋嵵緔 提交于 2019-12-13 22:18:44
问题 I'm having trouble wrapping my head around the concept of an assignment operator, or at least creating them successfully. Copy Constructors aren't an issue for me; here is mine that its working: //copy constructor Set::Set(const Set &rhs){ _head = rhs._head; _tail = rhs._tail; //null, basically this object is 0 if(rhs._head == NULL){ _head = NULL; _tail = NULL; _size = 0; }else{ _head = new Elem(*rhs._head); _tail = new Elem(*rhs._tail); _size = rhs._size; Elem *prev = NULL; Elem *curr =

Double Linked List

夙愿已清 提交于 2019-12-13 22:13:41
问题 //I have a single linked list that looks like this node head = new Node (); head.info = 3; head.next = new Node (); head.next.info = 6 (); head.next.next = new Node (); head.next.next.info = 9; head.next.next.next = null; //How would I write a double linked list? class Double Node { info; doubleNode prev; doubleNode next; } 回答1: Here is the part for creating a double linked list and adding nodes to it. You can update it by adding remove and insert functions as you want. class Node{ Node prev;

popping out a number from a stack list (linked list)?

人走茶凉 提交于 2019-12-13 20:24:48
问题 class stack_class { private: struct stack_struct *head; public: stack_class(); ~stack_class(); void pushNumber(int number); void popNumber(); void findNumber(); void clearStack(); void sizeFinder(); void printStack(); }; void stack_class::popNumber() { stack_struct *pointerPop=NULL,*pointerPop2=NULL; int popCounter=0,i=0; pointerPop2=tailPointer; if(head==NULL) { cout<<"\nNo Member to Delete.\n"; } else { while(pointerPop2) { popCounter++; //cout<<pointerFunc3->number<<endl; pointerPop2

What is Node *& aNode? [duplicate]

寵の児 提交于 2019-12-13 19:50:58
问题 This question already has answers here : Can someone help me understand this? int *& pr [duplicate] (3 answers) What does *& mean in a function parameter (5 answers) Closed 6 years ago . In the following code: void insert(Node *& aNode, int x) { if (!aNode) { aNode = new Node(x); aNode->next = aNode; return; } Node *p = aNode; Node *prev = NULL; do { prev = p; p = p->next; if (x <= p->data && x >= prev->data) break; // For case 1) if ((prev->data > p->data) && (x < p->data || x > prev->data))

Selection sort with linked list's

和自甴很熟 提交于 2019-12-13 18:29:34
问题 I have the following data structure: struct scoreentry_node { struct scoreentry_node *next; int score; char name[1]; }; typedef struct scoreentry_node *score_entry; I am trying to create a function that consumes my structure in order and arranges them in ascending order based on the name. I want to modify the input without allocating any memory or freeing anything: I've tried your suggestions: void selectionsort(score_entry *a) { for (; *a != NULL; *a = (*a)->next) { score_entry *minafteri =