This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
class Stack | |
{ | |
private: | |
class node | |
{ | |
public: | |
int data; | |
node *next; | |
node() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
class Stack | |
{ | |
private: | |
class node | |
{ | |
public: | |
int data; | |
node *next; | |
node() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class node | |
{ | |
public: | |
int data; | |
node *next; | |
node() | |
{ | |
next=NULL; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void append(int val) | |
{ | |
Size++; | |
node *temp=new node(); | |
temp->data=val; | |
if(Head==NULL) | |
{ | |
Head=tail=temp; | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void add(int pos,int val) | |
{ | |
node *temp=new node(); | |
temp->data=val; | |
if(pos==0) | |
{ | |
Size++; | |
temp->next=Head; | |
Head=temp; | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Delete(int pos) | |
{ | |
node *temp,*left,*right; | |
if(pos==0) | |
{ | |
Size--; | |
temp=Head; | |
Head=Head->next; | |
delete(temp); | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void show() | |
{ | |
node *temp=Head; | |
while(temp!=NULL) | |
{ | |
cout<<temp->data<<" "; | |
temp=temp->next; | |
} | |
cout<<endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<iostream> | |
using namespace std; | |
class List | |
{ | |
private: | |
class node | |
{ | |
public: | |
int data; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Compute_ST(int N) | |
{ | |
for (int i=0;i<N;i++)ST[0][i] = i; | |
for (int k = 1;(1 << k)<N; k++) | |
{ | |
for (int i=0;i+(1<<k)<=N;i++) | |
{ | |
int x = ST[k-1][i]; | |
int y = ST[k-1][i+(1<<k-1)]; | |
ST[k][i]=A[x]<=A[y]?x:y; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int RMQ(int i, int j) | |
{ | |
int k = log2(j-i); | |
int x = ST[k][i]; | |
int y = ST[k][j-(1<<k)+1]; | |
return A[x] <= A[y] ? x : y; | |
} |
OlderNewer