mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 05:21:49 +03:00
Update stack_using_linked_lists.c
This commit is contained in:
parent
b282b95d5b
commit
752cde71ef
@ -16,8 +16,8 @@ int main()
|
|||||||
printf("\t****stack using linked list****\n");
|
printf("\t****stack using linked list****\n");
|
||||||
while (x != 4)
|
while (x != 4)
|
||||||
{
|
{
|
||||||
printf("enter your choice");
|
printf("\n1. Push\n2. Pop\n3. Display\n4. Exit\n");
|
||||||
printf("\n1.push\n2.pop\n3.display\n4.exit\n");
|
printf("Enter your choice: ");
|
||||||
scanf("%d", &x);
|
scanf("%d", &x);
|
||||||
switch (x)
|
switch (x)
|
||||||
{
|
{
|
||||||
@ -41,14 +41,14 @@ void push(struct node *p)
|
|||||||
int item;
|
int item;
|
||||||
struct node *temp;
|
struct node *temp;
|
||||||
temp = (struct node *)malloc(sizeof(struct node));
|
temp = (struct node *)malloc(sizeof(struct node));
|
||||||
printf("enter element to be inserted\n");
|
printf("\nEnter element to be inserted: ");
|
||||||
scanf("%d", &item);
|
scanf("%d", &item);
|
||||||
temp->info = item;
|
temp->info = item;
|
||||||
|
|
||||||
temp->link = top;
|
temp->link = top;
|
||||||
top = temp;
|
top = temp;
|
||||||
|
|
||||||
printf("inserted succesfully\n");
|
printf("Inserted succesfully.\n");
|
||||||
}
|
}
|
||||||
void pop(struct node *p)
|
void pop(struct node *p)
|
||||||
{
|
{
|
||||||
@ -56,27 +56,27 @@ void pop(struct node *p)
|
|||||||
struct node *temp;
|
struct node *temp;
|
||||||
|
|
||||||
if (top == NULL)
|
if (top == NULL)
|
||||||
printf("stack is empty\n");
|
printf("\nStack is empty.\n");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
item = top->info;
|
item = top->info;
|
||||||
temp = top;
|
temp = top;
|
||||||
top = top->link;
|
top = top->link;
|
||||||
free(temp);
|
free(temp);
|
||||||
printf("Element popped is%d\n", item);
|
printf("\nElement popped is %d.\n", item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void display(struct node *p)
|
void display(struct node *p)
|
||||||
{
|
{
|
||||||
if (top == NULL)
|
if (top == NULL)
|
||||||
printf("stack is empty\n");
|
printf("\nStack is empty.\n");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Elements in the stack are\n");
|
printf("\nElements in the stack are:\n");
|
||||||
while (p != NULL)
|
while (p != NULL)
|
||||||
{
|
{
|
||||||
printf("%d\n", p->info);
|
printf("\t%d\n", p->info);
|
||||||
p = p->link;
|
p = p->link;
|
||||||
}
|
}
|
||||||
// printf("%d\n",p->info);
|
// printf("%d\n",p->info);
|
||||||
|
Loading…
Reference in New Issue
Block a user