<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Data structure | Student Projects</title>
	<atom:link href="https://studentprojects.in/category/software-development/cpp/cpp-programs/cpp-data-structure/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Sat, 10 Dec 2022 04:53:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>How to return Nth the node from the end of the linked list in one pass</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-return-nth-the-node-from-the-end-of-the-linked-list-in-one-pass/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-return-nth-the-node-from-the-end-of-the-linked-list-in-one-pass/#respond</comments>
		
		<dc:creator><![CDATA[Chitra]]></dc:creator>
		<pubDate>Tue, 12 Apr 2022 14:07:44 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9040</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<pre class="wp-block-code"><code lang="cpp" class="language-cpp">Node * GetNthNode(Node * Head, int NthNode) {
  Node * pNthNode = NULL;
  Node * pTempNode = NULL;
  int nCurrentElement = 0;

  for (pTempNode = Head; pTempNode != NULL; pTempNode = pTempNode -> pNext) {
    nCurrentElement++;
    if (nCurrentElement - NthNode == 0) {
      pNthNode = Head;
    } else
    if (nCurrentElement - NthNode > 0) {
      pNthNode = pNthNode -> pNext;
    }
  }
  if (pNthNode) {
    return pNthNode;
  } else
    return NULL;
}</code></pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-return-nth-the-node-from-the-end-of-the-linked-list-in-one-pass/">How to return Nth the node from the end of the linked list in one pass</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-return-nth-the-node-from-the-end-of-the-linked-list-in-one-pass/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to print a data from a binary tree in-order(ascending)</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-print-a-data-from-a-binary-tree-in-orderascending/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-print-a-data-from-a-binary-tree-in-orderascending/#respond</comments>
		
		<dc:creator><![CDATA[Chitra]]></dc:creator>
		<pubDate>Tue, 12 Apr 2022 13:47:37 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9030</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<pre class="wp-block-code"><code lang="cpp" class="language-cpp">//
// recursive version
//

Void PrintTree(struct * node node) {
  if (node == NULL)
    return;

  PrintTree(node -> left);
  Printf(“ % d”, node -> data);
  PrintTree(node -> right);
}</code></pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-print-a-data-from-a-binary-tree-in-orderascending/">How to print a data from a binary tree in-order(ascending)</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-print-a-data-from-a-binary-tree-in-orderascending/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to insert a node into a sorted linked list</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-insert-a-node-into-a-sorted-linked-list/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-insert-a-node-into-a-sorted-linked-list/#respond</comments>
		
		<dc:creator><![CDATA[Chitra]]></dc:creator>
		<pubDate>Tue, 12 Apr 2022 05:15:41 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9018</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<pre class="wp-block-code"><code lang="cpp" class="language-cpp">void sortedInsert(Node * head, Node * newNode) {
  Node * current = head;

  // traverse the list until you find item bigger the // new node value
  //	
  while (current != NULL &amp;&amp; current -> data &lt; newNode -> data) {
    current = current -> next);
}
//
// insert the new node before the big item
//
newNode -> next = current -> next;
current = newNode;
}</code></pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-insert-a-node-into-a-sorted-linked-list/">How to insert a node into a sorted linked list</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-insert-a-node-into-a-sorted-linked-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to sort a linked list</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-sort-a-linked-list/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-sort-a-linked-list/#respond</comments>
		
		<dc:creator><![CDATA[Chitra]]></dc:creator>
		<pubDate>Tue, 12 Apr 2022 05:02:36 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9014</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<pre class="wp-block-code"><code lang="cpp" class="language-cpp">//sorting in descending order
struct node {
  int value;
  node * NEXT;
}
//Assume HEAD pointer denotes the first element in the //linked list
// only change the values…don’t have to change the //pointers

Sort(Node * Head) {
  node * first, second, temp;
  first = Head;
  while (first != null) {
    second = first -> NEXT;
    while (second != null) {
      if (first -> value &lt; second -> value) {
        temp = new node();
        temp -> value = first -> value;
        first -> value = second -> value;
        second -> value = temp -> value;
        delete temp;
      }
      second = second -> NEXT;
    }

    first = first -> NEXT;
  }
}</code></pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-sort-a-linked-list/">How to sort a linked list</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-sort-a-linked-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to delete a node in a double linked list</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-delete-a-node-in-a-double-linked-list/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-delete-a-node-in-a-double-linked-list/#respond</comments>
		
		<dc:creator><![CDATA[Chitra]]></dc:creator>
		<pubDate>Tue, 12 Apr 2022 04:59:19 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9012</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<pre class="wp-block-code"><code lang="cpp" class="language-cpp">void deleteNode(node *n)
{
node *np = n->prev;
node *nn = n->next;
np->next = n->next;
nn->prev = n->prev;
delete n;
}</code></pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-delete-a-node-in-a-double-linked-list/">How to delete a node in a double linked list</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-delete-a-node-in-a-double-linked-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to reverse a singly linked list</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-reverse-a-singly-linked-list/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-reverse-a-singly-linked-list/#respond</comments>
		
		<dc:creator><![CDATA[Chitra]]></dc:creator>
		<pubDate>Tue, 12 Apr 2022 04:58:11 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9010</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<pre class="wp-block-code"><code lang="cpp" class="language-cpp">//
// iterative version
//
Node* ReverseList( Node ** List )	
{

	Node *temp1 = *List;
	Node * temp2 = NULL;
	Node * temp3 = NULL;

	while ( temp1 )
	{
		*List = temp1; //set the head to last node		
temp2= temp1->pNext; // save the next ptr in temp2
		temp1->pNext = temp3; // change next to privous
		temp3 = temp1;
		temp1 = temp2;
	}
 
	return *List;
}
</code></pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-reverse-a-singly-linked-list/">How to reverse a singly linked list</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/how-to-reverse-a-singly-linked-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Program to solve travelling sales person problem using dynamic programming</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-solve-travelling-sales-person-problem-using-dynamic-programming/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-solve-travelling-sales-person-problem-using-dynamic-programming/#respond</comments>
		
		<dc:creator><![CDATA[Chitra]]></dc:creator>
		<pubDate>Fri, 08 Apr 2022 04:23:45 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=8988</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<pre class="wp-block-code"><code lang="cpp" class="language-cpp">// program to solve travelling sales person problem using dynamic programming

#include &lt;iostream.h>
#include&lt;conio.h>

#define MAX 100
#define INFINITY 999

class travel
{
	private:
		int n; /* Number of cities. */
		int i, j; /* Loop counters. */
		int c[MAX][MAX]; /* Cost matrix. */
		int tour[MAX]; /* Tour matrix. */
		int cost; /* Least cost. */
		int tsp_dp (int c[][MAX], int tour[], int start, int n);

	public:
		int tsp();
		void setdata();
		void getdata();
};

int travel::tsp()
{
	return(tsp_dp(c,tour,0,n));
}

void travel::setdata()
{
	cout&lt;&lt;"\nHow many cities to traverse? ";
	cin>>n;

	cout&lt;&lt;"\nEnter the cost matrix: (999: no connection)\n";
	for(i=0;i&lt;n;i++)
	{
		cout&lt;&lt;"\nEnter "&lt;&lt;i+1&lt;&lt;" row: ";
		for(j=0;j&lt;n;j++)
			cin>>c[i][j];
	}

	for(i=0;i&lt;n;i++)
		tour[i]=i;

}

void travel::getdata()
{
	for (i=0; i&lt;n; i++)
		cout&lt;&lt;tour[i]+1&lt;&lt;"\t";
	cout&lt;&lt;"1\n";
}

int travel::tsp_dp (int c[][MAX], int tour[], int start, int n)
{
	int i, j, k; /* Loop counters. */
	int temp[MAX]; /* Temporary during calculations. */
	int mintour[MAX]; /* Minimal tour array. */
	int mincost; /* Minimal cost. */
	int ccost; /* Current cost. */

	/* End of recursion condition. */
	if(start==n-2)
		return c[tour[n-2]][tour[n-1]] + c[tour[n-1]][0];

/* Compute the tour starting from the current city. */
	mincost = INFINITY;
	for(i=start+1;i&lt;n;i++)
	{
		for(j=0;j&lt;n;j++)
			temp[j]=tour[j];

/* Adjust positions. */
		temp[start+1]=tour[i];
		temp[i]=tour[start+1];

/* Found a better cycle? (Recurrence derivable.) */
		if (c[tour[start]][tour[i]] +
				(ccost = tsp_dp (c, temp, start+1, n)) &lt; mincost)
		{
			mincost=c[tour[start]][tour[i]]+ccost;
			for(k=0;k&lt;n;k++)
				mintour[k]=temp[k];
		}
	}

	/* Set the minimum-tour array. */
	for(i=0;i&lt;n;i++)
		tour[i]=mintour[i];

	return mincost;
}

void main()
{
	int cost;
	travel t;
	clrscr();

	t.setdata();

	cost = t.tsp();
	cout&lt;&lt;"\n\n\tMinimum cost: "&lt;&lt;cost;
	cout&lt;&lt;"\n\n\tTour: \t";

	t.getdata();

	getch();
}</code></pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-solve-travelling-sales-person-problem-using-dynamic-programming/">Program to solve travelling sales person problem using dynamic programming</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-solve-travelling-sales-person-problem-using-dynamic-programming/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Program to solve optimal binary search tree problem with dynamic programming</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-solve-optimal-binary-search-tree-problem-with-dynamic-programming/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-solve-optimal-binary-search-tree-problem-with-dynamic-programming/#respond</comments>
		
		<dc:creator><![CDATA[Chitra]]></dc:creator>
		<pubDate>Fri, 08 Apr 2022 04:22:46 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=8986</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<pre class="wp-block-code"><code lang="cpp" class="language-cpp">// program to solve optimal binary search tree problem with dynamic programming

#include&lt;iostream.h>
#include&lt;conio.h>

struct node
{
	int data;
	struct node *left,*right;
};

typedef struct node node;

class binary
{
	private:
		int w[10][10],c[10][10],r[10][10],n;
		int p[10],q[11];

		int find(int,int);
		node *cnst_tree(int,int);

	public:
		void obst();
		void setdata();
		node *tree();
};

node *binary::tree()
{
	return(cnst_tree(0,n));
}

void binary :: setdata()
{
	int i,j;

	cout&lt;&lt;"\nEnter number of identifiers: ";
	cin>>n;

	cout&lt;&lt;"\nEnter values for P vector ("&lt;&lt;n&lt;&lt;" values): ";
	for(i=1;i&lt;=n;i++)
		cin>>p[i];

	cout&lt;&lt;"\nEnter values for Q vector ("&lt;&lt;n+1&lt;&lt;" values): ";
	for(i=0;i&lt;=n;i++)
		cin>>q[i];
}

void binary :: obst()
{
	int i,j,k,m;

	for(i=0;i&lt;=n-1;i++)
	{
		w[i][i]=q[i];
		r[i][i]=0;
		c[i][i]=0;

		w[i][i+1]=p[i+1]+q[i+1]+q[i];
		r[i][i+1]=i+1;
		c[i][i+1]=w[i][i+1];
	}

	w[n][n]=q[n];
	r[n][n]=0;
	c[n][n]=0;

	for(m=2;m&lt;=n;m++)
		for(i=0;i&lt;=n-m;i++)
		{
			j=i+m;
			w[i][j]=w[i][j-1]+p[j]+q[j];
			k=find(i,j);
			c[i][j]=w[i][j]+c[i][k-1]+c[k][j];
			r[i][j]=k;
		}
}

int binary ::find(int i,int j)
{
	int min=32767,m,l;

	m=r[i][j-1];
	while(m&lt;=r[i+1][j])
	{
		if(c[i][m-1]+c[m][j]&lt;min)
		{
			min=c[i][m-1]+c[m][j];
			l=m;
		}
		m++;
	}

	return l;
}

node * binary::cnst_tree(int i,int j)
{
	int k;
	node *p= new node;
	k=r[i][j];

	if(k==0)
		return NULL;
	else
	{
		p->data=k;
		p->left=cnst_tree(i,k-1);
		p->right=cnst_tree(k,j);
		return p;
	}
}

void inorder (node *x)
{
	if(x)
	{
		inorder(x->left);
		cout&lt;&lt;x->data&lt;&lt;"\t";
		inorder(x->right);
	}
}

void main()
{
	node *root;
	binary b;
	clrscr();

	b.setdata();

	b.obst();

	root=b.tree();

	cout&lt;&lt;"\nTree in inorder traversal is: \n\n\t";
	inorder(root);

	getch();
}


</code></pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-solve-optimal-binary-search-tree-problem-with-dynamic-programming/">Program to solve optimal binary search tree problem with dynamic programming</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-solve-optimal-binary-search-tree-problem-with-dynamic-programming/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Program to solve knapsack problem using backtracking problem</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-solve-knapsack-problem-using-backtracking-problem/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-solve-knapsack-problem-using-backtracking-problem/#respond</comments>
		
		<dc:creator><![CDATA[Chitra]]></dc:creator>
		<pubDate>Fri, 08 Apr 2022 04:22:06 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=8984</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<pre class="wp-block-code"><code lang="cpp" class="language-cpp">// program to solve knapsack problem using backtracking problem

#include&lt;iostream.h>
#include&lt;conio.h>

class knapsack
{
	private:
		int p[20],w[20],m,x[20],y[20],n;
		int Bound(int,int,int);
		int fp,fw;

	public:
		knapsack()
		{
			fp=0;
		}
		void BKnap(int,int,int);
		void setdata();
		void getdata();
};

void knapsack::setdata()
{
	int i;

	cout&lt;&lt;"\nEnter number of elements: ";
	cin>>n;

	cout&lt;&lt;"\nEnter elements in the descending order of P/W\n";

	for(i=1;i&lt;=n;i++)
	{
		cout&lt;&lt;"\nEnter profit of "&lt;&lt;i&lt;&lt;" element: ";
		cin>>p[i];
		cout&lt;&lt;"\nEnter weight of "&lt;&lt;i&lt;&lt;" element: ";
		cin>>w[i];
	}

	cout&lt;&lt;"\nEnter capcity of kanpsack: ";
	cin>>m;
}

int knapsack::Bound(int cp,int cw,int k)
{
	int b,c,i;

	b=cp;
	c=cw;

	for(i=k+1;i&lt;=n;i++)
	{
		c=c+w[i];
		if(c&lt;m)
			b=b+p[i];
		else
			return (b+(1-(c-m)/w[i]) * p[i]);
	}
	return b;
}

void knapsack::BKnap(int k,int cp,int cw)
{
	int j;

	if(cw+w[k]&lt;=m)
	{
		y[k]=1;
		if(k&lt;n)
			BKnap(k+1,cp+p[k],cw+w[k]);
		if((cp+p[k]>fp) &amp;&amp; (k==n))
		{
			fp=cp+p[k];
			fw=cw+w[k];
			for(j=1;j&lt;=k;j++)
				x[j]=y[j];
		}
	}

	if(Bound(cp,cw,k)>=fp)
	{
		y[k]=0;
		if(k&lt;n)
			BKnap(k+1,cp,cw);
		if((cp>fp) &amp;&amp; (k==n))
		{
			fp=cp;
			fw=cw;
			for(j=1;j&lt;=k;j++)
				x[j]=y[j];
		}
	}
}

void knapsack::getdata()
{
	int i;

	for(i=1;i&lt;=n;i++)
		cout&lt;&lt;"x["&lt;&lt;i&lt;&lt;"]= "&lt;&lt;x[i]&lt;&lt;endl;
}

void main()
{
	knapsack k;

	k.setdata();

	k.BKnap(1,0,0);

	cout&lt;&lt;"\nSolution is :\n";
	k.getdata();

	getch();
}


</code></pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-solve-knapsack-problem-using-backtracking-problem/">Program to solve knapsack problem using backtracking problem</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-solve-knapsack-problem-using-backtracking-problem/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Program to solve all pairs shortest path problem using dynamic programming</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-solve-all-pairs-shortest-path-problem-using-dynamic-programming/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-solve-all-pairs-shortest-path-problem-using-dynamic-programming/#respond</comments>
		
		<dc:creator><![CDATA[Chitra]]></dc:creator>
		<pubDate>Fri, 08 Apr 2022 04:21:22 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=8982</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<pre class="wp-block-code"><code lang="cpp" class="language-cpp">// program to solve all pairs shortest path problem using dynamic programming

#include&lt;iostream.h>
#include&lt;conio.h>

class graph
{
	int cost[20][20],n,a[20][20];

	public:
		void setdata();
		void getdata();
		void path();
};

void graph::setdata()
{
	int i,j,k;

	cout&lt;&lt;"\nEnter number of nodes: ";
	cin>>n;

	cout&lt;&lt;"\nEnter Cost matrix (32767 for infinity): ";

	for(i=1;i&lt;=n;i++)
	{
		cout&lt;&lt;"\nEnter "&lt;&lt;i&lt;&lt;"row :";
		for(j=1;j&lt;=n;j++)
			cin>>cost[i][j];
	}
}

void graph::getdata()
{
	int i,j;

	for(i=1;i&lt;=n;i++)
	{
		for(j=1;j&lt;=n;j++)
			cout&lt;&lt;a[i][j]&lt;&lt;"\t";
		cout&lt;&lt;"\n\n";
	}
}

void graph::path()
{
	int i,j,k,l;

	for(i=1;i&lt;=n;i++)
		for(j=1;j&lt;=n;j++)
			a[i][j]=cost[i][j];

	for(k=1;k&lt;=n;k++)
		for(i=1;i&lt;=n;i++)
			for(j=1;j&lt;=n;j++)
			{
				l=a[i][k]+a[k][j];
				a[i][j]=(a[i][j]>l)?l:a[i][j];
			}
}

void main()
{
	graph g;
	clrscr();

	g.setdata();
	g.path();

	cout&lt;&lt;"\nMatrix with Shortest paths is: \n\n";
	g.getdata();

	getch();
}</code></pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-solve-all-pairs-shortest-path-problem-using-dynamic-programming/">Program to solve all pairs shortest path problem using dynamic programming</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-solve-all-pairs-shortest-path-problem-using-dynamic-programming/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
