[C程序字符串倒序输出]你的函数没有返回值。 把a,b两个数组设为全局变量就好了。 就这样就行了: #include "stdio.h" char a[20],b[20]; char str(char a[],char b[]) { int m=19,n; for(n=0;m>-1;n+...+阅读
//单链表的逆序输出分为两种情况,一种是只逆序输出,实际上不逆序;另一种是把链表逆序//本文就分别实例讲述一下两种方法。具体如下://1.逆序输出//实例代码如下:#include#include#include using namespace std; typedef struct node{ int data; node * next; }node;//尾部添加 node * add(int n, node * head){ node * t = new node; t->data = n; t->next = NULL; if (head == NULL){ head = t; } else if (head->next == NULL){ head->next = t; } else{ node * p = head->next; while (p->next != NULL){ p = p->next; } p->next = t; } return head; }//顺序输出 void print(node * head){ node * p = head; while (p != NULL){ cout data p = p->next; } cout }//递归 void reversePrint(node * p){ if (p != NULL){ reversePrint(p->next); cout data } }//栈 void reversePrint2(node * head){ stack s; while (head != NULL){ s.push(head->data); head = head->next; } while (!s.empty()){ cout s.pop(); } } int main(){ node * head = NULL; for (int i = 1; i head = add(i, head); } print(head); reversePrint(head); reversePrint2(head); system("pause"); return 0; }//2.单链表逆序//实例代码如下:#include#include#include using namespace std; typedef struct node{ int data; node * next; }node; node * add(int n, node * head){ node * t = new node; t->data = n; t->next = NULL; if (head == NULL){ head = t; } else if (head->next == NULL){ head->next = t; } else{ node * p = head->next; while (p->next != NULL){ p = p->next; } p->next = t; } return head; }//循环 node * reverse(node * head){ if (head == NULL || head->next == NULL){ return head; } node * p1 = head; node * p2 = head->next; node * p3 = NULL; head->next = NULL; while (p2 != NULL){ p3 = p2; p2 = p2->next; p3->next = p1; p1 = p3; } head = p1; return head; } void print(node * head){ node * p = head; while (p != NULL){ cout data p = p->next; } cout }//递归 node * reverse2(node * p){ if (p == NULL || p->next == NULL){ return p; } node * newHead = reverse2(p->next); p->next->next = p; p->next = NULL; return newHead; } int main(){ node * head = NULL; for (int i = 1; i head = add(i, head); } print(head); head = reverse(head); print(head); head = reverse2(head); print(head); system("pause"); return 0; }
以下为关联文档:
用C语言编程:常见字符串倒序输出的程序给个例子: #include<stdio.h> int main() {char s[100],*p; gets(s); for(p=s;*p;p++); for(;p>=s;p--) printf("%c",*p); printf("\n"); getch(); return 0; }...
你好请问一下怎么用C语言编写单链表插入节点程序万分感谢!#include "sll_node.h" #include #define FALSE 0 #define TRUE 1 // insertNode2:把newValue的值插入到递增排序的链表中,正确返回TRUE,错误返回FALSE // nextp是指向当前节点的...
用c语言编译个程序第三题: #include<stdio.h> void main() { int m, n, m1, n1, t; printf("input n,m:"); scanf("%d,%d", &n, &m); if (n < m) { m1 = m; n1 = n; } else { m1 = n; n1 = m; } do...
c语言输入一个整数用递归算法将整数倒序输出#include voidorder_print(intn) { if(n{ printf("%d",n); return; } order_print(n/10); printf("%5d",n%10); } void reverse_print(intn) { if(n{ printf("%-5d",n); return; }...
急!求c语言单链表冒泡排序的详细流程图#include struct number { int num; struct number *next; }; void main() { struct number *head; struct number *p1,*p2,*p,*p3,*p4; int n=0,m,i,j; p1=p2=(struct numb...
如何用c语言实现单链表的逆置1、算法的核心就是reverse函数,其它的都是辅助建立链表和输出链表的。从数据结构的定义来看这是一个带头节点的链表。要弄的十分明白要耐心点画图看看。 2、思路:head是指向头...
单链表排序问题C语言经典算法--单链表选择排序第一种:#include#includetypedef struct node{ int data; struct node *next; }*Linklist,Node; Linklist creat(int n) {Linklist head,r,p; int x...
怎么用C语言写单链表的排序从键盘输入不定数量的数字构造链表,输入0结束,然后排序输出,代码如下: #include <stdio.h> #include <stdlib.h> #include <conio.h> typedef struct _list { int val; struct _...
在数据结构中用c语言怎么编写用单链表将26个字母排序的程序#include #include //申明链表 typedef struct node { char num; struct node *next; }list; void Bubble_sort(list *L);//链表的冒泡排序 void Dis_list(list *L);//遍历单...