The Push() function is used to insert data, but before inserting we need to check wheteher the stack is full or not because if the stack is already full we cannot carry out the push operation this is also called as stack overflow, else if there's space insert the new element and increment the top pointer. ![]() functions/operations performed by a stackįirst we need learn two important functions namely push and pop to insert and remove data from the stack Push () These operations are: Push The push operation adds a new element to the stack. Approach: To insert a node at the start/beginning/front of a Linked List, we need to: Make the first node of Linked List linked to the new node Remove the head from the original first node of Linked List Make the new node as the Head of the Linked List. Also you should check for malloc () return. ![]() However the strcpy in your addNote functions might not do what you want (don't use strcpy), and you are adding nodes at the beginning of the list instead of the end. In the code below, first we create a class Stack in which we'll add an array to store the data and then a pointer top which helps us to interact and perform various functions of a stack altogether class Stack essentially to add nodes to your linked list inside your list you would do head2->head addlinkednode (head2->head, text2 i). To implement stack using array we need an array of required size and top pointer to insert/delete data from the stack and by default top=-1 i.e the stack is empty.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |