Showing posts with label Structure. Show all posts
Showing posts with label Structure. Show all posts

WAP of stack using structure and that needs to perform push & pop operation

/*WAP of stack using structure and that needs to perform push & pop operation*/
#include<iostream.h>
#include<conio.h>
//using namespace std;
void stack();
void push(int);
int pop();
struct stack
{
//private:
int arr[5],top;
//public:
}s;
void stack()
{
s.top=-1;
}
void push(int v)
{
if(s.top==4)
cout<<"Stack is full"<<endl;
else
{
s.arr[++s.top]=v;
cout<<"Data pushed successfully"<<endl;
}
}
int pop()
{
if(s.top==-1)
{
cout<<"Stack is empty"<<endl;
return NULL;
}
else
return s.arr[s.top--];
}
main()
{
///stack s;
int ch,k;
stack();
cout<<"1 for push\n2for pop";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter Variable";
cin>>k;
push(k);
break;
case 2:
cout<<pop();
break;
}
getch();
}

WAP of LINKED lIST insert front , print , delet front in single linked list

/*WAP of LINKED lIST insert front , print , delet front in single linked list*/
#include<stdio.h>
#include<conio.h>

void insert_front_sl();
void print_sl();
void insert_end_sl();

struct node
{
	int data;
	struct node *link;
};
struct node *header;

void main()
{
	clrscr();
	
	header = (struct node *) malloc(sizeof(struct node));
	header->data = NULL;
	header->link = NULL;
	
	insert_front_sl();
	insert_front_sl();
	print_sl();
	insert_end_sl();
	insert_end_sl();
	print_sl();
	
	getch();
}

void insert_front_sl()
{
	struct node *temp,*ptr;
	int X;
	temp = (struct node *) malloc(sizeof(struct node));
	
	if(temp == NULL)
	{
		printf("Memory Insufficient");
	}
	else
	{
		ptr = header->link;
		
		printf("\nEnter the value to insert at front: ");
		scanf("%d", &X);
		temp->data = X;
		temp->link = ptr;
		header->link = temp;
	}
}

void print_sl()
{
	struct node *ptr;
	ptr = header;
	
	while(ptr->link != NULL)
	{
		ptr = ptr->link;
		printf("%d ",ptr->data);
	}
}

void insert_end_sl()
{
	struct node *temp,*ptr;
	int X;
	temp = (struct node *) malloc(sizeof(struct node));
	
	if(temp == NULL)
	{
		printf("Memory Insufficient");
	}
	else
	{
		ptr = header;
		while(ptr->link != NULL)
		{
			ptr = ptr->link;
		}
		
		printf("\nEnter the value to insert at end: ");
		scanf("%d", &X);
		temp->data = X;
		temp->link = NULL;
		ptr->link = temp;
	}
}


WAP to illustrate the use of time.h header file

/*WAP to illustrate the use of time.h header file*/
#include <stdio.h>
#include <time.h>

main(){


	time_t time_val;
	struct tm *tp;
	char buffer[100];
	
	time_val = time(NULL);
	printf("Time_Value: %li\n",time_val);

	tp = localtime(&time_val);

	printf("Hours:%d, Minutes:%d, Seconds:%d\n",
	        tp->tm_hour, tp->tm_min, tp->tm_sec);

	printf("asctime()==%s\n",asctime(tp));

	strftime(buffer, 99, "%A %B %d %Y at %I:%M:%S%p", tp);
	printf("%s\n",buffer);

}

WAP to write code of fake torjan virus using structure

/*WAP to write code of fake torjan virus using structure*/
#include<stdio.h>
#include<conio.h>
#include<string.h>

struct date
{
    int day,month,year;
    char path[100];
}d;

int main()
{
  printf("Enter Day");
  scanf("%d",&d.day);

  printf("Enter Month");
  scanf("%d",&d.month);

  printf("Enter Year");
  scanf("%d",&d.year);

  printf("Your Date is successfully saved\n\n\tDate\t%d/%d/%d",d.day,d.month,d.year);

  printf("Enter Path of file");
  scannf("%s",&d.path);

  getch();
  return(0);
}