### How can I write a function for a linked list that inserts? How can I write a remove function?

Hello, everyone.

Currently a bit confused as to how to write my insert and delete functions.

I am using a linked list class and trying to implement these functions to no avail.

Can anyone help me write these functions.

This is my code right now.

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 #include #include #include #include class Node { public: int data; Node * next; Node(int x){ data = x; next = NULL; } Node(int x, Node * y){ data = x; next = y; } }; class SortedLinkedList { Node *head; public: SortedLinkedList(){ head = NULL; } void addANode(int value){ Node *p; if(head == NULL) head = new Node (value, NULL); else{ p=head; while(p->next !=NULL) p=p->next; p->next = new Node (value, NULL); } } void print(){ Node * p; p = head; while(p != NULL){ if (p->data>=0){ std::cout << p->data << "\n";} p = p->next; } } int sortedGetLength() { int count = 0; Node * iterator = head; while(iterator != 0){ count++; iterator = iterator->next;} std::cout<data==x){ return true;} p=p->first;} while(first->next!=NULL);} return false; } void SortedDelete(int k, int &x, bool& success) { Node *temp = front, *prev = 0; for(int i = 0;i < size; i++) { if (temp == n) { if (temp == front) { front = n->next; } else { prev->next = temp->next; } delete temp; size --; return true; } prev = temp; temp = temp->next; } } };
Topic archived. No new replies allowed.