rkc1.NITD
BAN USER- 0 Answers data structure
this is c program to check balanced paranthesis using stack,
- rkc1.NITD September 05, 2014
i dnt know whats wrong it always showing balanced expression.
tell me what i am doing wrong.??#include<stdio.h>
void main()
{
char stk[50],exp[100];
int top=-1,i;
printf("enter an expression\n");
gets(exp);
for(i=0;exp[i]!='\0';i++)
{
if(exp[i]=='('|| exp[i]=='['||exp[i]=='{')
{
top++;
stk[top]=exp[i];
}
else
if(exp[i]=')')
{
if(stk[top]=='(')
top--;
}
else
{
printf("unbalanced exp\n");
break;
}
if(exp[i]=']')
{
if(stk[top]=='[')
top--;
}
else
{
printf("unbalanced exp\n");
break;
}
if(exp[i]='}')
{
if(stk[top]=='{')
top--;
}
else
{
printf("unbalanced exp\n");
break;
}
}
if(top==-1)
printf("exp is balanced\n");
else
printf("exp is not balanced\n");
}| Flag | PURGE - 4 Answers linked list problem
it is c program for inserting a node at the beginning of link list,..plz fix the errors in this program.
- rkc1.NITD August 23, 2014
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node* next;
};
struct node* head;
void insert(int x)
{
struct node* temp=(node*)malloc(sizeof(struct node));
temp->data=x;
temp->next=NULL;
head=temp;
if(head!=NULL)
{
temp->next=head;
head=temp;
}
else
{
temp->next=head;
head=temp;
}
void print()
{
struct node* temp=head;
printf("list is: ");
while(temp!=NULL)
{
printf("%d",temp->data);
temp=temp->next;
}
printf("\n");
}
int main()
{
head=NULL; /*empty list*/
int n,i,x;
printf("how many no you want to add?\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter the no.:\n");
scanf("%d",&x);
insert(x);
print();
}
return 0;
}| Flag | PURGE