Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct Node{
- int data;
- struct Node* next;
- };
- typedef struct Node node;
- node* head;
- void Push(int x){
- node* newnode = (node*)malloc(sizeof(node*));
- //Initializing new node
- newnode->data = x;
- newnode->next = NULL;
- if(head==NULL){
- head = newnode;
- return;
- }
- //Linking
- newnode->next = head;
- head = newnode;
- }
- void Pop(){
- if(head==NULL){
- printf("No elements present");
- }
- node* temp = head;
- head=temp->next;
- free(temp);
- }
- void Print(){
- node* temp = head;
- while(temp!=NULL){
- printf("%d-->", temp->data);
- temp = temp->next;
- }
- printf("\n");
- }
- int main(){
- head = NULL;
- Push(5);
- Push(3);
- Print();
- Push(7);
- Print();
- Pop();
- Print();
- // do{
- // printf("Enter the operation you want to perform \n1) Push 2) Insert 3)Remove 4)Delete 5) Print Linked List 6) Stop \n");
- // scanf("%d", &n);
- // switch(n){
- // case 1: {
- // printf("Enter the number to be inserted at 1st position \n");
- // scanf("%d", &c);
- // Push(c);
- // printf("Linked List Updated:- ");
- // Print();
- // printf("\n");
- // };
- // break;
- // case 2: {
- // printf("Enter the number to be inserted at nth position \n");
- // scanf("%d", &c);
- // printf("Enter nth position");
- // scanf("%d", &pos);
- // Insert(c, pos);
- // printf("Linked List Updated:- ");
- // Print();
- // printf("\n");
- // };
- // break;
- // case 3: {
- // printf("Number deleted from 1st position \n");;
- // Remove();
- // printf("Linked List Updated:- ");
- // Print();
- // printf("\n");
- // };
- // break;
- // case 4: {
- // printf("Enter the position at which the number is to be deleted \n");
- // scanf("%d", &pos);
- // Delete(pos);
- // printf("Linked List Updated:- ");
- // Print();
- // printf("\n");
- // };
- // break;
- // case 5: Print();
- // break;
- // case 6: return 0;
- // break;
- // default: printf("Wrong Input \n");
- // break;
- // }
- // }while(1>0);
- return 0;
- }
Add Comment
Please, Sign In to add comment