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

ADDITIONAL LEARNING

TEAM MEMBERS REGISTRATION NUMBER


SHIVAM SARASWAT 18BIT0061

SHRIDHAR PRABHUDESAI 18BIT0058

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 str[100]; // define an array for stack

int op=0; // intialize the counter for number of combinations

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

for (i = l; i <= r; i++)

push(str[l]);

push(str[i]);

str[l]=pop();

str[i]=pop();

permute(str, l+1, r);

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;

}*head=NULL;

int n;

int main()

void input();

node *reverse(node*);

void display();

char ch='y';

int choice;

while(ch=='y')

cout<<"Enter 1 to enter 2 to display 3 to reverse"<<endl;

cin>>choice;

switch (choice)

case 1:

input();

break;

}
case 2:

display();

break;

case 3:

reverse(head);

break;

cout<<"Enter y to continue operations n to exit"<<endl;

cin>>ch;

return 0;

void input()// to input the values of the linked list

cout<<"Enter no of values in list"<<endl;

cin>>n;

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

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

node *temp=new node;

node *ptr=head;

temp->next=NULL;

cin>>temp->data;

if(head==NULL)

{
head=temp;

else

while(ptr->next!=NULL)

ptr=ptr->next;

ptr->next=temp;

void display()//to display the linked list

node *ptr=head;

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

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

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

else

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

ptr=ptr->next;

node *reverse(node *ptr)//recurrsive function to swap pairs

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: