Вы находитесь на странице: 1из 9

## TEAM MEMBERS REGISTRATION NUMBER

SHIVAM SARASWAT 18BIT0061

## SHREEYA BHUWALKA 18BIT0120

EVENT: CODE-A-THON

Ques-10)

Q-10)-a

CODE:-
#include <stdio.h>

#include <string.h>

int stack[2];

int top=-1;

int data;

int n ;

## int push(int x) // define push for stack str

data=x;

if(top==-1)

stack[0]=data;

top++;

else

stack[++top]=data;

## int pop() //define pop for stack str

int temp;

temp=stack[top];

top--;

return temp;

}
void permute(int str[], int l, int r) // define a permutation function

int i;

if (l == r)

{printf("combination- %d ->",op);

for(int k=0;k<n;k++)

printf("%d", str[k]);

op++;

printf("\n");}

else

push(str[l]);

push(str[i]);

str[l]=pop();

str[i]=pop();

push(str[l]);

push(str[i]);

str[l]=pop();

str[i]=pop();

int main()
{

## printf("Total number of terms(n) : ");

scanf("%d",&n);

printf("enter values:");

for(int i=0;i<n;i++)

{ scanf("%d",&str[i]);

## void permute(int[] ,int,int);

permute(str, 0, n-1);

return 0;

OUTPUT:
Q-10)-b

CODE:-

#include<iostream>

## using namespace std;

struct node

int data;

node *next;

int n;

int main()

void input();

node *reverse(node*);

void display();

char ch='y';

int choice;

while(ch=='y')

cin>>choice;

switch (choice)

case 1:

input();

break;

}
case 2:

display();

break;

case 3:

break;

cin>>ch;

return 0;

cin>>n;

## cout<<"Enter the values"<<endl;

for(int i=0;i<n;i++)

## node *temp=new node;

temp->next=NULL;

cin>>temp->data;

{

else

while(ptr->next!=NULL)

ptr=ptr->next;

ptr->next=temp;

## void display()//to display the linked list

for(int i=0;i<n;i++)

{if(i!=(n-1))

cout<<ptr->data<<"->";

else

cout<<ptr->data<<"->x"<<endl;

ptr=ptr->next;

int temp=0;

## node *temp1=new node;

if(ptr->next==NULL);
else

{ temp=ptr->data;

ptr->data=ptr->next->data;

ptr->next->data=temp;

if(ptr->next->next!=NULL)

temp1=ptr->next->next;

reverse(temp1);

OUTPUT: