Question: Implement a stack with linked lists using the Linked List implementation I supplied. For push use insert end, for pop use remove from end. //

Implement a stack with linked lists using the Linked List implementation I supplied. For push use insert end, for pop use remove from end.

 Implement a stack with linked lists using the Linked List implementation
I supplied. For push use insert end, for pop use remove from
end. // LinkedList.cpp : Defines the entry point for the console application.
II \#include "stdafx.h" \#include \#include \#include \#include \#include "conio. h" \#include struct
Node { int data; struct Node * Next; \}i//declaration of a Node

// LinkedList.cpp : Defines the entry point for the console application. II \#include "stdafx.h" \#include \#include \#include \#include \#include "conio. h" \#include struct Node { int data; struct Node * Next; \}i//declaration of a Node struct Node *head = NULL;// two pointers to struct Node type of data //global definition of head void insertFirst(int d)// if the head was not globally defined it should be coming with parameter struct Node "hd \{ struct Node newNode =( struct Node ) malloc(sizeof(struct Node)); newNode data = d; newNode Next = head > Next; head Next = newNode; printf(")n new node inserted in the first placeln"); 3 void insertLast(int d, struct Node nnod) \{ struct Node * temp = (struct Node* ) malloc(sizeof(struct Node)); temp = head; while(temp->Next !=NULL) temp = temp > Next; I/when the loop terminates it means we found last node /ow temp is the last node with Next=null temp > Next = nnod; nnod > Next = NULL; nnod data =d; printf("|n new node inserted in the last placeln" ); 3 void insertAfterNodeWith_d(int d, int newdata) //when loop terminates we have last node in temp, the previos of last in prev prev->Next = NULL; // we do not need the last node any more free ( temp); printf("In last node is deleted (n); 3 void deleteNodeWithData(int d)//deleting the node having data d \{ struct Node *temp =( struct Node ) malloc(sizeof(struct Node)); temp = head; struct Node * prev = NULL;//to hold the node before the one with data d while (( temp->Next != NULL) &( temp > data !=d)){ prev = temp; temp = temp > Next; } //when the loop terminates it means we found last node or the node with data=d if (temp data == d) {/ now temp is the node with data=d, prev is the node before it prev->Next = temp->Next; free(temp); printf("In node with data \%d is deleted , d); 3/ we do not need the node with data =4 any more else printf("In node with data \%d could not be found In", d); 3 int searchData(int d) \{ struct Node *temp =( struct Node ) malloc(sizeof(struct Node)); temp = head; int index =0; while (( temp->Next != NULL) &( temp->data != d) ) \{temp = temp Next; index++; \} if (temp->data ==d ) \{ return index

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!