linked-list

Trying to make linkedlist in C

帅比萌擦擦* 提交于 2019-12-02 12:18:22
I am trying to make a struct in C that is a linked list. I am not really sure what is going wrong though. My errors are: linked.c:6:2: error: unknown type name ‘linkedList’ linked.c: In function ‘makeList’: linked.c:30:2: error: ‘first’ undeclared (first use in this function) linked.c:30:2: note: each undeclared identifier is reported only once for each function it appears in linked.c: In function ‘addToList’: linked.c:36:9: error: used struct type value where scalar is required linked.c:43:13: error: incompatible types when assigning to type ‘int *’ from type ‘linkedList’ if anybody can see

singly linked chain printing c++

与世无争的帅哥 提交于 2019-12-02 11:46:21
I am trying to pick my chain in the format {1,2,3,4,etc}. You can find the header file below which will have the layout of the nodes. I am just confused on how I should go about cycling through my list to print out Item. Any guidance would be greatly appreciated! set.h using namespace std; #include <iostream> class Set { private: struct Node { int Item; // User data item Node * Succ; // Link to the node's successor }; unsigned Num; // Current count of items in the set Node * Head; // Link to the head of the chain public: // Return information about the set // bool is_empty() const { return Num

Inserting a node into a linked list in constant-time?

流过昼夜 提交于 2019-12-02 11:44:30
问题 I'm working on an assignment that is telling me to assume that I have a singly linked list with a header and tail nodes. It wants me to insert an item y before position p. Can anybody please look over my code and tell me if I'm on the right track? If not, can you provide me with any tips or pointers (no pun intended)? tmp = new Node(); tmp.element = p.element; tmp.next = p.next; p.element = y; p.next = tmp; I think I may be wrong because I do not utilize the header and tail nodes at all even

How to delete two items in a row in a linked list

别来无恙 提交于 2019-12-02 10:51:10
问题 void delete_double (LN<T>*& l) { if (l == nullptr) return; LN<T> *p = l; while ( p -> next != nullptr && p -> next -> next != nullptr) { if (p -> value == p -> next -> value) // the current value is equal to the next value in the linked list { if (p == l) // when the first two values are the same // not sure if it is correct { l = l -> next -> next; } else // Problem should be here { LN<T> *to_delete = p; // Also tried this (doesn't work) p = p->next; delete to_delete; // LN<T>* to_delete = p

Reversing a singly linked list in C [duplicate]

别说谁变了你拦得住时间么 提交于 2019-12-02 10:41:50
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to reverse a singly linked list using only two pointers? This is C code to reverse a linked list. But this isn't producing the desired output. struct node *temp,*prev; while(head->next!=NULL) { temp=prev=head; while(temp->next->next!=NULL) { temp=temp->next; prev=prev->next; } temp=temp->next; temp->next=prev; prev->next=NULL; } What am I missing? 回答1: You don't provide enough informations to have more

Singly-Linked List in Rust

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 10:41:20
问题 I've been trying to teach myself some Rust lately and wanted to practice a bit by implementing a simple linked list. I took some inspiration from the Rust library's linked list and tried to replicate the parts I already understood. Also I decided to make it singly-linked for now. struct Node<T> { element: T, next: Option<Box<Node<T>>>, } impl<T> Node<T> { fn new(element: T) -> Self { Node { element: element, next: None, } } fn append(&mut self, element: Box<Node<T>>) { self.next = Some

My program replaces all the string data types in all the nodes in the linked list

只愿长相守 提交于 2019-12-02 10:00:19
问题 I have a program that basically adds a history(node) to the employee_record(linked list). Here is my code: #include <stdio.h> #include <stdlib.h> struct history{ char *department1; char *title1; int day; int month; int year; struct history *next; }; struct employee_record{ char firstname[20]; char lastname[20]; long int employee_id; char sex; int age; struct history *head; }; void addjob(struct employee_record *rec, char *department, char *title, int day, int month, int year); void print

print() function that prints the contents of each element of your list

社会主义新天地 提交于 2019-12-02 09:52:17
Basically i'm trying to write a print statement that will allow me to print the elements per line as a println as the output when i run the driver.java. And for the life of me i cannot figure out how to do it. Any help will be appreciated. here is the driver.java public class Driver { public static void main(String args[]){ LList<String> s_list = new LList<String>(); s_list.insert("New York, 8.4M"); s_list.insert("Los Angeles 3.8M"); s_list.insert("Chicago, 2.7M"); s_list.insert("Houston, 2.1M"); s_list.insert("Philadelphia, 1.55M"); s_list.insert("Phoenix, 1.51M"); s_list.append("San Antonio,

Remove all nodes in linked list

佐手、 提交于 2019-12-02 09:46:24
I have a linked list contains 3 nodes like the image shown: There is a head pointer and temp1 pointer point to the front of the list, and tail point points at the end of the list. I want to remove all the nodes, and change it back to its original initial form ( tail = NULL, head = first_node , but the first node doesn't have any value in the data and next field). Because I want to start putting up some new values in it. To remove all those data, is this code going to remove nodes inside this linked list and left with the first node with no values in data and next field? This code is in C++:

Creating a linked list with a for loop

心已入冬 提交于 2019-12-02 09:45:26
Here is my struct struct ListItem{ int data; struct ListItem *next; }; Assuming the first node of the linked list will have data = 0, I want to write a for loop that creates a linked list of size 5 but I'm not sure how to work I tried the following int main(int argc, char* argv[]){ struct ListItem a; a.data = 0; for (int i = 1; i < 5; i++){ struct ListItem *pointer = &a; struct ListItem nextnode; nextnode.data = i; a.next = &nextnode; pointer = pointer->next; } } But the result is a.data = 0 and a.next->data = 4 Don't modify a. Take a temp node starting as a. Make it's next point to the new