Posts

Showing posts with the label cplusplus

Thank you, next! Linked List in C++; Lesson 5

Image
Hope you are following us from our first post about linked list, if so! lets continue with our linked list lesson, if not, don't worry, you can start form the beginning, here are links for you to review our previous lessons: Linked List; Lesson 1   Linked List; Lesson 2   Linked List; Lesson 3   Linked List; Lesson 4   Alright! lets begin our fifth lesson i.e deleting node.Now this is a feature of linked list which array doesn't provide. You can always overwrite any value in array but you cant delete it, but linked list gives you the opportunity to do so. Say, you have a linked list of 4 nodes and you are tasked to delete a node from that linked list asked by user at run time (This code will be quite similar to insert node code). For this, you'll be codding del() as follows: void del() {     node *temp = new node; //1     node *temp1 = new node; //2     node *temp2 = new node; //3    ...

Thank you, next! Linked List in C++; Lesson 4

Image
Hope you are following us from our first post about linked list, if so! lets continue with our linked list lesson, if not, don't worry, you can start form the beginning, here are links for you to review our previous lessons: Linked List; Lesson 1   Linked List; Lesson 2   Linked List; Lesson 3   Alright! lets begin our 4th lesson. As we previously learnt about creating nodes and printing by using concept of linked list, further we learnt about inserting new node at head position and a t some given/specified position. So today we'll try to insert nodes at: At position specified by user at run time.   At position specified by user at run time: If you understood lesson 3,this will be a piece of cake for you. So what we are trying to do here is just to replace a specific position in code with the position given at run time by user. For this you'll be codding insert() as follows: void insert() {     node *temp = new nod...

Thank you, next! Linked List in C++; Lesson 3

Image
Hope you are following us from our first post about linked list, if so! lets continue with our linked list lesson, if not, don't worry, you can start form the beginning, here is a link for you to review our previous lessons: Linked List; Lesson 1   Linked List; Lesson 2   Alright! lets begin our third lesson. As we previously learnt about creating nodes and printing by using concept of linked list, further we learnt about inserting new node at head position. So today we'll try to insert nodes at: At some given/specified position.   Insert node at some given/ specified position:   Suppose you have a linked list with (say) three nodes and you are required to insert new node such as, after second node i.e your new node will become third node,third node will become forth node and so on. For this, you'll be codding insert() as follows: void insert() {     node *temp = new node; //1     node *temp1 = new...

Thank you, next! Linked List in C++; Lesson 2

Image
Hope you are following us from our first post about linked list, if so! lets continue with our linked list lesson, if not, don't worry, you can start form the beginning, here is a link for you to review our first lesson: Linked List; Lesson 1   Alright! lets begin our second lesson. As we previously learnt about creating nodes and printing by using concept of linked list, today we'll try to insert nodes at various locations At head node. At some given position. At position specified by user at run time.     Insert node at head node: Now we hope and assume you grasped the concept of linked list quite well from our first lesson, so first lets jump to insert_start() function. Suppose you have a linked list with (say) three nodes and you are required to insert new node such that it replaces head node,i.e your new node will become head node,head node will become second node and so on. For this, you'll be codding insert_start() as follows: void insert...

Thank you, next! Linked List in C++; Lesson 1

Image
Couldn't let this opportunity just slide away! Lets talk about Linked List.  Linked list is basically a linear data structure which doesn't require consecutive memory location unlike array, rather it use pointers to point at next node. So you could say its can be used as alternative to array. To understand the concept, lets consider a linked list with three nodes,including the head node,something like the figure bellow: Here, each node consists of two parts, a part to store data and a part to store address of the next node, further we observe that there is a pointer that points to head node , this pointer is, you can say, the most important part of linked list as you can use this pointer to get to any node you want, also there is a pointer that points the last node ,this pointer too, plays very important role. Other than taking you directly to last node, it helps in adding new nodes. It may sound a bit overwhelming for now but trust me! Its very interestin...