Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions Linkedlist/LinkedListJazib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#include<stdio.h>
#include<stdlib.h>

int count=0;

struct node{
int a;
struct node *link;
}*head,*ptr;


void push(){
printf("Current count is %d\n",count);
int b,pos,i;
ptr=(struct node*)malloc(sizeof(struct node));
struct node *current;
struct node *prev;
printf("Enter the element you want to insert\n");
scanf("%d",&b);
printf("Enter the position\n");
scanf("%d",&pos);
if(pos>count+1||pos<0){
printf("Position does not exist\n");
return;
}
ptr->a=b;
ptr->link=NULL;

if(head==NULL){
head=ptr;
count++;
}

else{
if(pos==1){
ptr->link=head;
head=ptr;
count++;
}

else{
current=head;
for(i=1;i<=count;i++){
if(pos-1==i){
ptr->link=current->link;
current->link=ptr;
count++;
break;
}
current=current->link;
}
}
}
}


void pop(){
int pos,i;
struct node *current;
if(head==NULL){
printf("Underflow\n");
return;
}
printf("Enter the position\n");
scanf("%d",&pos);

if(pos>count||pos<0){
printf("Position does not exist\n");
return;
}

if(pos==1){
ptr=head;
head=head->link;
free(ptr);
count--;
}
else {
current=head;
for(i=1;i<=count;i++){
if(pos-1==i){
ptr=current->link;
current->link=current->link->link;
free(ptr);
count--;
break;
}
current=current->link;
}
}
}

void print(){
if(head==NULL){
printf("\nEmpty\n\n");
return;
}
ptr=head;
printf("\n");
while(ptr!=NULL){
printf("%d ",ptr->a);
ptr=ptr->link;
}
printf("\n\n");
}

void rev(){
struct node *current;
struct node *prev;
struct node *next;
prev=NULL;
current=head;
next=head;
while(current!=NULL){
next=next->link;
current->link=prev;
prev = current;
current = next;
}
head=prev;

}

int main(){
int choice;
do{
printf("Enter your choice\n");
printf("1. Push\n2. Pop\n3. Reverse\n4. Print\n5. Exit\n");
scanf("%d",&choice);
switch(choice){
case 1: push();
break;
case 2: pop();
break;
case 3: rev();
break;
case 4: print();
break;
}
}while(choice!=5);
return 0;
}
81 changes: 81 additions & 0 deletions Queues/QueueUsingPointerJazib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include<stdio.h>
#include<stdlib.h>


struct node{
int a;
struct node *link;
}*front,*ptr,*rear;


void push(){
int b;
ptr=(struct node*)malloc(sizeof(struct node));
printf("Enter the element you want to insert\n");
scanf("%d",&b);
ptr->a=b;
ptr->link=NULL;
if(front==NULL&&rear==NULL){
front=ptr;
rear=ptr;
}
else {
rear->link=ptr;
rear=ptr;
}
}


void pop(){
struct node *ptr;
if(front==NULL&&rear==NULL){
printf("Underflow\n");
return;
}
if(front==rear){
ptr=front;
free(ptr);
front=NULL;
rear=NULL;
}
else {
ptr=front;
front=front->link;
free(ptr);
}
}

void print(){
struct node *ptr;
if(front==NULL){
printf("\nEmpty\n\n");
return;
}
ptr=front;
printf("\n");
while(ptr!=NULL){
printf("%d ",ptr->a);
ptr=ptr->link;
}
printf("\n\n");
}

int main(){
int choice,b;
front=NULL;
rear=NULL;
do{
printf("Enter your choice\n");
printf("1. Push\n2. Pop\n3. Print\n4. Exit\n");
scanf("%d",&choice);
switch(choice){
case 1: push();
break;
case 2: pop();
break;
case 3: print();
break;
}
}while(choice!=4);
return 0;
}
52 changes: 52 additions & 0 deletions Stacks/stackUsingArrayJazib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include<stdio.h>
int a[5],f=-1;


void push(){
int b;
if(f==4){
printf("Overflow\n");
return;
}
printf("Enter the element you want to insert\n");
scanf("%d",&b);
f++;
a[f]=b;
}


void pop(){
if(f==-1){
printf("Underflow\n");
return;
}
f--;
}

void print(){
int i;
for(i=0;i<=f;i++){
printf("%d ",a[i]);
}
printf("\n");
}

int main(){
int choice;
do{
printf("Enter your choice\n");
printf("1. Push\n2. Pop\n3. Print\n4. Exit\n");
scanf("%d",&choice);
switch(choice){
case 1: push();
break;
case 2: pop();
break;
case 3: print();
break;
}
}while(choice!=4);


return 0;
}
69 changes: 69 additions & 0 deletions Stacks/stackUsingPointerJazib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include<stdio.h>
#include<stdlib.h>


struct node{
int a;
struct node *link;
}*top,*ptr;


void push(){
int b;
ptr=(struct node*)malloc(sizeof(struct node));
printf("Enter the element you want to insert\n");
scanf("%d",&b);
ptr->a=b;
ptr->link=NULL;
if(top==NULL)
top=ptr;
else {
ptr->link=top;
top=ptr;
}
}


void pop(){
struct node *ptr;
if(top==NULL){
printf("Underflow\n");
return;
}
ptr=top;
top = top -> link;
free(ptr);
}

void print(){
struct node *ptr;
if(top==NULL){
printf("Empty\n");
return;
}
ptr=top;
while(ptr!=NULL){
printf("%d ",ptr->a);
ptr=ptr->link;
}
printf("\n");
}

int main(){
int choice,b;
top=NULL;
do{
printf("Enter your choice\n");
printf("1. Push\n2. Pop\n3. Print\n4. Exit\n");
scanf("%d",&choice);
switch(choice){
case 1: push();
break;
case 2: pop();
break;
case 3: print();
break;
}
}while(choice!=4);
return 0;
}