Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
LinkedList
#include <iostream> using namespace std; class LinkedList; class Node { friend class LinkedList; private: int data; Node *next; }; class LinkedList() { private: Node *head; public: LinkedList { head = 0; } ~LinkedList() { Node *curr = head; Node * temp; while(curr!=0) { temp = curr->next; delete curr; curr = temp; } head = 0; } bool InsertAtStart(int val) { Node *temp = new Node; if(temp!=0) { temp->data = val; temp->next = 0; head = temp; return true; } else { return false; } } bool InsertAtEnd(int val) { Node *temp = new Node; Node *curr = head; Node *prev = 0; if(temp!=0) { temp->data = val; temp->next = 0; while(curr!=0) { prev = curr; curr = curr->next; } if(prev == 0) { head = temp; } else { prev->next = temp; } return true; } else { return false; } } void display() { Node *curr = head; while (curr!=0) { cout << curr; curr = curr->next; } } }; int main() { cout << "Hello World" << endl; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
VC++ windows exception
Dequeue Using STL List
cv4_template
DCapSurfaceDesc
Fast sine to fill array (sin/cos pair)
hangman
parantheses matching test 1
asock
Replace all spaces in a string in C++
Hangman
Please log in to post a comment.