diff --git a/C++/Program_26/README.md b/C++/Program_26/README.md new file mode 100644 index 00000000..ab77102f --- /dev/null +++ b/C++/Program_26/README.md @@ -0,0 +1 @@ +Program to implement Stack DataStructure Using Linked Lists \ No newline at end of file diff --git a/C++/Program_26/StacksUsingLL.cpp b/C++/Program_26/StacksUsingLL.cpp new file mode 100644 index 00000000..219da729 --- /dev/null +++ b/C++/Program_26/StacksUsingLL.cpp @@ -0,0 +1,73 @@ +//Stacks Using Linked_Lists +#include +using namespace std; +class node{ + public: + int data; + node *link; +}*top=NULL; + +void push(int x){ + node *t; + t = new node; + if(t==NULL){ + cout<<"Stack is full[Satck overflow]"<data = x; + t->link = top; + top = t; + } +} + +void display(node *p){ + while(p){ + cout<data<<" "; + p = p->link; + } + cout<link; + x = p->data; + delete p; + } + return x; + +} + +int main(){ + + int x; + char c; + while(1){ + cout<<"Choose an Operation : \n1.Push\n2.Pop\n3.Display\n4.Exit"<>c; + switch (c) + { + case '1': + cout<<"Enter the element : "; + cin>>x; + push(x); + break; + case '2': + x=pop(); + cout<<"Poped element is "< +using namespace std; +class node{ + public: + int c; + int e; + node *link; +}*P=NULL; + +void create(){ + node *last,*t; + int n; + cout<<"Enter the NUmber of Terms : "; + cin>>n; + cout<<"Enter all the Terms in coeffient and exponent form : "<> t->c >> t->e; + t->link = NULL; + if(P==NULL) + last = P = t; + else{ + last->link = t; + last = t; + } + } + +} + +double evalute(int x){ + node *t = P; + double sum = 0.0; + while(t){ + sum += t->c*pow(x,t->e); + t = t->link; + } + return sum; +} + +int main(){ + int n; + create(); + cout<<"Enter the Value of x : "; + cin>>n; + double r = evalute(n); + cout<<"The value of the polynomial expression when x = "<