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
64 changes: 64 additions & 0 deletions C/infix2post.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include<stdio.h>

#define size 100
char arr[size];
top= -1;

void push(char x){
top++;
arr[top]=x;
}
void pop(){
if(arr[top]!='(')
printf("%c",arr[top]);
top--;
}

int pr(char c){
if(c=='+' || c=='-'){
return 1;
}
else if(c=='*' || c=='/' || c=='%'){
return 2;
}
else
return -1;
}
int isalnum(char c){
if((c>='a' && c<='z')||(c>='A' && c<='B')|| (c>='1' && c<='9'))
return 1;
else
return 0;
}
int main(){

char a[size];
printf("exp:");
scanf("%s",a);
for(int i=0; a[i]!= '\0';i++){
if(isalnum(a[i])){
printf("%c",a[i]);
}
else{
if(top==-1 || a[i]=='(')
push(a[i]);
else if(a[i]==')'){
while(arr[top]!='('){
pop();
}
}
else {
while(pr(a[i])<=pr(arr[top]) && top>=0 && pr(a[i])!=-1){
pop();
}
push(a[i]);
}
}
}
while (top>=0)
{
pop();
}

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

struct node
{
int data;
struct node * next;
};
struct node * top=NULL;

void push(int x){
struct node *newnode;
newnode=(struct node *)malloc(sizeof(struct node));
newnode->next=NULL;
newnode->data=x;

if(top==NULL){
top=newnode;
}
else{
newnode->next=top;
top=newnode;
}
}

void pop(){
struct node * current=top;
if(top!=NULL)
{
top=current->next;
free(current);
}
else printf("no elements");
}

void display(){
struct node * current=top;
while(current!=NULL){
printf("%d ",current->data);
current=current->next;
}
}

void main(){
int option=0;
int d;
while(1){
printf("\n1.push\t2.pop\t3.show\t0.exit:");
scanf("%d",&option);
switch (option)
{
case 1:
printf("data:");scanf("%d",&d);
push(d);
break;
case 2:
pop();
break;
case 3:
display();
break;
case 0:
exit(0);
default:
break;
}
}
}