We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#include <stdio.h> #include<stdlib.h> struct node { struct node next; int data; }; void push(struct node*); void pop(struct node**); void display(struct node*); void peek(struct node*); int main() { struct node *top = 0; int choice; printf("Enter 1 to Push\nEnter 2 for Pop\nEnter 3 for Display\nEnter 4 for Peek\nEnter 5 for Exit\n"); do { printf("\nEnter you choice: "); scanf("%d", &choice); switch (choice) { case 1: push(&top); break;
case 2: if (top == 0) { printf("Stack is Empty"); break; } else { pop(&top); break; } case 3: if(top==0) { printf("Stack is Empty"); break; } else { display(top); break; } case 4: if(top==0) { printf("Stack is Empty"); break; } else { peek(top); } case 5: break; default: printf("Invalid Choice"); } }while(choice!=5);
} void push(struct node top) { struct node newnode; newnode=(struct node)malloc(sizeof(struct node)); printf("Enter the data: "); scanf("%d",&newnode->data); newnode->next=(*top); (*top)=newnode;
} void pop(struct node **top) { printf("The popped element is %d",(*top)->data); struct node *temp=(*top); (*top)=(*top)->next; free(temp); }
void display(struct node* top) { struct node temp=top; printf("The elements in the stack are: "); while(temp!=0) { printf("%d ",temp->data); temp=temp->next; } } void peek(struct node top) { printf("The topmost element is %d",top->data); }
The text was updated successfully, but these errors were encountered:
please see this code and accept in hacktoberfest
Sorry, something went wrong.
No branches or pull requests
#include <stdio.h>
#include<stdlib.h>
struct node
{
struct node next;
int data;
};
void push(struct node*);
void pop(struct node**);
void display(struct node*);
void peek(struct node*);
int main()
{
struct node *top = 0;
int choice;
printf("Enter 1 to Push\nEnter 2 for Pop\nEnter 3 for Display\nEnter 4 for Peek\nEnter 5 for Exit\n");
do
{
printf("\nEnter you choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
push(&top);
break;
}
void push(struct node top)
{
struct node newnode;
newnode=(struct node)malloc(sizeof(struct node));
printf("Enter the data: ");
scanf("%d",&newnode->data);
newnode->next=(*top);
(*top)=newnode;
}
void pop(struct node **top)
{
printf("The popped element is %d",(*top)->data);
struct node *temp=(*top);
(*top)=(*top)->next;
free(temp);
}
void display(struct node* top)
{
struct node temp=top;
printf("The elements in the stack are: ");
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}
}
void peek(struct node top)
{
printf("The topmost element is %d",top->data);
}
The text was updated successfully, but these errors were encountered: