0% found this document useful (0 votes)
90 views3 pages

Lab Manual Signals

1. The document provides instructions for a lab manual assignment on implementing a stack using a linked list as the underlying data structure in C. 2. It includes an algorithm and C implementation for the push() operation, and assigns students to write algorithms and code for the pop(), display(), and main() functions to complete the linked list stack implementation. 3. It also asks students to explain their understanding of the malloc() function used in the implementations.

Uploaded by

Engr. Abdullah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views3 pages

Lab Manual Signals

1. The document provides instructions for a lab manual assignment on implementing a stack using a linked list as the underlying data structure in C. 2. It includes an algorithm and C implementation for the push() operation, and assigns students to write algorithms and code for the pop(), display(), and main() functions to complete the linked list stack implementation. 3. It also asks students to explain their understanding of the malloc() function used in the implementations.

Uploaded by

Engr. Abdullah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab Manual /Assignment (5)

Linked List Implementation of Stack

Student Name:--------------------------------Date: 13-04-2011 Roll No:------------------------------------------Grades: ---------------------

Instructions: All tasks should be completed in the coming Lab Session to get full credit. You must show the output and code of each task to the instructor. Attach separate A4 sheets with manual to complete the assignments if needed. Copying codes and assignments will only lead to embarrassment. So avoid it. Reading: [1] Data Structures and Algorithm Analysis in C by Mark Allen Weiss [2] Data Structures using C and C++ by Langsam, Augenstein, Tenebaum

Algorithm for push() operation


Suppose TOP is a pointer, which is pointing towards the topmost element of the stack. TOP is NULL when the stack is empty. DATA is the data item to be pushed. 1. Input the DATA to be pushed
1/10

2. 3. 4. 5. 6.

Creat a New Node NewNode DATA = DATA NewNode Next = TOP TOP = NewNode Exit

C Implementation for push() operation

#include<conio.h> #include<stdio.h> #include<malloc.h> #include<process.h> //Structure is created a node struct node { int info; struct node *link;//A link to the next node }; //A variable named NODE is been defined for the structure typedef struct node *NODE; //This function is to perform the push operation NODE push(NODE top) { NODE NewNode; int pushed_item; //A new node is created dynamically NewNode = (NODE)malloc(sizeof(struct node));
2/10

printf(\nInput the new value to be pushed on the stack:); scanf(%d,&pushed_item); NewNode->info=pushed_item;//Data is pushed to the stack NewNode->link=top;//Link pointer is set to the next node top=NewNode;//Top pointer is set return(top); }/*End of push()*/ Assignment 1. Write an algorithm for pop() operation of stack using linked list as underlying data structure. 2. Write a C implementation for pop() operation of stack using linked list as underlying data structure. 3. Write a C implementation for display() operation {to display all the elements present in stack}of stack using linked list as underlying data structure. 4. Write a main() program to integrate all above operations of stack in a single application. Hint: Follow the same style adopted in Implementation of stack using Arrays. 5. Explain your understanding about malloc() function used in above implementations.

3/10

You might also like