Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C languange : Can someone help me modify the stack single linked-Iist Code, so it becomes the phone log? Where the console, the output should

C languange : Can someone help me modify the stack single linked-Iist Code, so it becomes the phone log?

 

Where the console, the output should be displays as follows :

-------Welcome-------- [1] Create [2] Display [3] Delete [4] Quit

Enter your choice: 1

 

Enter First name: Alex Enter number: 09988776

FULL NAME | PHONE NUMBER ------------------------------------------------------------- Alex | 09988776

 

Do you want to quit? 1 for no / 0 for yes: 1

 

-------Welcome-------- [1] Create [2] Delete [3] Display [4] Quit

Enter your choice: 2

FULL NAME | PHONE NUMBER ----------------------------------------------------------- Alex | 09988776

 

Do you want to quit? 1 for no / 0 for yes:

 

Below is the code that needs to modify:

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
// Demonstration of example of implement Stack with Single Linked List #include  #include  struct node { int data; //Data of the node struct node *nextptr; //Address of the next node }*HeadNode; const int MAXSIZE = 8; int Stack[8], top = -1; // Remark Refer follows link for more details on "?: ternary operator; // https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c-c/  int isempty() {return (top == -1)? 1 : 0;} int isfull() {return (top == MAXSIZE)? 1 : 0;} int peek() {return HeadNode->data;} int push(int data); void displayList(); int pop(); // Remark Refer follows link for more details on adding Color to printf() Output;  // https://www.theurbanpenguin.com/4184-2/void print_green() {printf("\033[1;32m");} void print_green() {printf("\033[1;32m");} void print_cyan() {printf("\033[1;36m");} void print_reset() {printf("\033[0m");} int main() { int opt, data; while(1){ printf("***Stack with Single Linked List***  "); printf(" [1] Push  "); printf(" [2] Pop  "); printf(" [3] Peak  "); printf(" [4] Exit  "); printf("Select Operation to the Stack :> "); scanf("%d", &opt); switch (opt){ case 1: printf("Input new insert data to the Stack:> "); scanf("%d", &data); push(data); displayList(); break; case 2: if (!isempty()) printf(">: Data \"%d\" pop out Stack:  ", data = pop()); else printf(":> Stack is empty. "); displayList(); break; case 3: if(!isempty()) printf(">: Element at top of the Stack: %d " ,peek()); else printf(">: Stack is empty. "); break; case 4: goto exitloop; default: printf (">: Error! No action being taken!  "); } } exitloop: ; return 0; } int push(int data) { struct node *stNode; if(!isfull()){ stNode = (struct node*)malloc(sizeof(struct node)); if(stNode == NULL) printf(" Memory can not be allocated."); else { top++; stNode->data = data; //Links the data part stNode->nextptr = NULL; if(HeadNode != NULL) stNode->nextptr = HeadNode; //Links the address part HeadNode = stNode; } }else printf(">: Could not insert data, Stack is full. "); } int pop() { int data; struct node *delNode; if(!isempty()){ delNode = HeadNode; data = delNode->data; HeadNode = HeadNode->nextptr; free(delNode); top--; return data; } else printf(">: Could not retrieve data, Stack is empty. "); } void displayList(){ struct node *stNode; print_green(); printf(">: Current data in Stack:  "); if(HeadNode == NULL) printf(" Stack is empty.  "); else { stNode = HeadNode; while(stNode != NULL){ printf(" Data = %d ", stNode->data); // prints the data of current node stNode = stNode->nextptr; // advances the position of current node } } print_reset(); } 
 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago